Linux网络配置点滴

1.在网络接口配置文件中(ifcfg-ethN),最多可以配置三个DNS选项(DNS1, DNS2, DNS3)
2.ifconfig – configure a network interface
(1). 显示所有网卡的配置信息
ifconfig
#or
ifconfig -a
(if a single -a argument is given, it displays the status of all interfaces)
(2). 显示eth0的配置信息
ifconfig eth0
(3). 配置网卡的地址
ifconfig eth0 192.168.1.23 netmask 255.255.255.0 up
(4). 打开/关闭网卡
ifconfig eth0 down && ifconfig eth0 up

ifdown eth0 && ifup eth0
(5). 设置MTU
ipconfig eth0 mtu 2000

echo “1499” > /sys/class/net/echo/mtu
(6). 为网卡添加另一个IP地址
ifconfig eth0:2 192.168.3.1 netmask 255.255.255.0 up

3. ip – show / manipulate routing, devices, policy routing and tunnels
(1). 显示网卡的三层地址信息
ip addr show eth0
(2). 显示网卡的二层地址信息
ip link show eth0
(3). 打开/关闭网卡
ip link set eth0 down && ip link set eth0 up
(4). 将网卡重命名(需要网卡先down掉)
ip link set eth0 name debugo
这个操作更推荐使用udev(/etc/udev/rules.d/70-persist*)来修改。
(5). 设置MTU
ip link set echo mtu 2000
(6). 为网卡添加另一个IP地址
ip addr add 192.168.3.1/24 dev eth0 label eth0:1
4. route – show / manipulate the IP routing table
(1). 显示路由表
-n不做主机名的方向解析(显示IP地址),同netstat -rn

(2). 删除一条路由(默认网关)
route del default gw 192.168.17.254
(3). 添加一条路由
route add default gw 192.168.17.1 dev eth0
5. dhclient – Dynamic Host Configuration Protocol Client
通过DHCP来获得eth0的地址
dhclient eth0
6. traceroute – print the route packets trace to network host
traceroute 192.168.17.1
7. host – – DNS lookup utility

8. nslookup – query Internet name servers interactively
nslookup host0或者交互式输入
nslookup
>host0
如果在/etc/resovle.conf中设置了search ,则自动加上域名,即host0.
9. tcpdump – dump traffic on a network (抓包工具)
监听eth0的包信息 tcpdump -i eth0
监控22(SSH)端口来自某一主机/网段的连接
$ tcpdump -i eth0 src host 172.19.6.1 and port 22
#或者 tcpdump -i eth0 src net 172.19.6.0 and port 22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
18:37:09.357180 IP 172.19.6.1.53678 > ub-debugo.localdomain.ssh: Flags [S], seq 504442529, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
18:37:09.357975 IP 172.19.6.1.53678 > ub-debugo.localdomain.ssh: Flags [.], ack 3523044451, win 256, length 0
18:37:09.358160 IP 172.19.6.1.53678 > ub-debugo.localdomain.ssh: Flags [P.], seq 0:47, ack 1, win 256, length 47
18:37:09.371546 IP 172.19.6.1.53678 > ub-debugo.localdomain.ssh: Flags [.], ack 1470, win 256, length 0
10. nc -arbitrary TCP and UDP connections and listens
(1). 检查对面主机的端口是否开启(-zSpecifies that nc should just scan for listening daemons)

(2). 开启一个监听,那么之后接受到的信息将直接输出到stdout上。
nc -l 10000
(3). 使用nc实现文件的传输
Server端开启监听
nc -l 10000 > 1.txt
Client端开启传输
nc 172.19.17.203 10000 < 1.txt ^^

Posted in Linux.