ifcfg命令家族:ifconfig,route,netstat
[root@node1 ~]# ifconfig eth1 0 #删除当前IP [root@node1 ~]# ifconfig eth1 eth1 Link encap:Ethernet HWaddr 00:0C:29:AE:E4:E2 inet6 addr: fe80::20c:29ff:feae:e4e2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:145 errors:0 dropped:0 overruns:0 frame:0 TX packets:18 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:16604 (16.2 KiB) TX bytes:1404 (1.3 KiB) [root@node1 ~]# ifconfig eth1 192.168.1.100/24 up [root@node1 ~]# ifconfig eth1 eth1 Link encap:Ethernet HWaddr 00:0C:29:AE:E4:E2 inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:feae:e4e2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:145 errors:0 dropped:0 overruns:0 frame:0 TX packets:18 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:16604 (16.2 KiB) TX bytes:1404 (1.3 KiB)
]# ifconfig eth1:0 192.168.1.101/24 #ifconfig添加IP必须加label,格式 IFACE:#
]# ifconfig eth1:0 eth1:0 Link encap:Ethernet HWaddr 00:0C:29:AE:E4:E2 inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
]# ifconfig eth1 up
]# ifconfig eth1 down
[root@node1 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
0.0.0.0 10.0.1.2 0.0.0.0 UG 0 0 0 eth0
]# route add -net 10.0.0.0/8 gw 192.168.1.1 dev eth1
]# route add default gw 192.168.1.1
]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
10.0.0.0 192.168.1.1 255.0.0.0 UG 0 0 0 eth1
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth1
0.0.0.0 10.0.1.2 0.0.0.0 UG 0 0 0 eth0
]# route del -net 10.0.0.0/8
]# route del default dev eth1
]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
0.0.0.0 10.0.1.2 0.0.0.0 UG 0 0 0 eth0
]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 10.0.1.2 0.0.0.0 UG 0 0 0 eth0
]# netstat -tan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 64 10.0.1.6:22 10.0.1.101:52600 ESTABLISHED
tcp 0 0 :::22 :::* LISTEN
]# netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 :::22 :::* LISTEN
]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 928/sshd
tcp 0 0 :::22 :::* LISTEN 928/sshd
]# netstat -i
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 4791 0 0 0 3900 0 0 0 BMRU
eth1 1500 0 1442 0 0 0 58 0 0 0 BMRU
lo 65536 0 12 0 0 0 12 0 0 0 LRU
]# netstat -Ieth1
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth1 1500 0 1446 0 0 0 58 0 0 0 BMRU
原创文章,作者:N24_ViCi,如若转载,请注明出处:http://www.178linux.com/61050
评论列表(1条)
对于网卡相关的知识,不仅要知道配置方式,也要知道如何查看当前网卡的流量,什么时候流量是高,什么时候网卡传输数据有异常,比如iftop工具等使用。