Linux 网络命令


查看是否安装iproute软件包【默认下,装系统时都会自动安装进去】
[root@smart202 ~]# rpm -qa | grep iproute
iproute-2.6.9-3.EL4.7
[root@smart202 ~]# rpm -ql iproute  【安装位置】
/etc/iproute2
/etc/iproute2/rt_dsfield
/etc/iproute2/rt_dsfield.rt_config
/etc/iproute2/rt_protos
/etc/iproute2/rt_protos.rt_config
/etc/iproute2/rt_realms
/etc/iproute2/rt_realms.rt_config
/etc/iproute2/rt_scopes
/etc/iproute2/rt_scopes.rt_config
/etc/iproute2/rt_tables
/etc/iproute2/rt_tables.rt_config
.......
+++++++++++++++++++++++++++++++++++++++
  常用命令:ip ,ip address,iproute
+++++++++++++++++++++++++++++++++++++++
ip
[root@smart202 ~]# ip link show
1: lo: mtu 16436 qdisc noqueue 
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
   link/ether 00:1c:c4:18:b5:ac brd ff:ff:ff:ff:ff:ff
3: eth1: mtu 1500 qdisc pfifo_fast qlen 1000
   link/ether 00:1c:f0:d5:56:aa brd ff:ff:ff:ff:ff:ff
4: sit0: mtu 1480 qdisc noop 
   link/sit 0.0.0.0 brd 0.0.0.0
[root@smart202 ~]# ip address show // 可以看到ipv4地址和ipv6地址
1: lo: mtu 16436 qdisc noqueue 
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 brd 127.255.255.255 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
   link/ether 00:1c:c4:18:b5:ac brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.202/24 brd 192.168.0.255 scope global eth0
    inet6 fe80::21c:c4ff:fe18:b5ac/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: mtu 1500 qdisc pfifo_fast qlen 1000
   link/ether 00:1c:f0:d5:56:aa brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.202/24 brd 192.168.100.255 scope global eth1
    inet6 fe80::21c:f0ff:fed5:56aa/64 scope link 
       valid_lft forever preferred_lft forever
4: sit0: mtu 1480 qdisc noop 
   link/sit 0.0.0.0 brd 0.0.0.0
[root@smart202 ~]# ip link set eth1 down  //关闭网卡eth1
[root@smart202 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:1C:C4:18:B5:AC  
          inet addr:192.168.0.202  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::21c:c4ff:fe18:b5ac/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1
          RX packets:151 errors:0 dropped:0 overruns:0 frame:0
          TX packets:100 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:17199 (16.7 KiB)  TX bytes:10042 (9.8 KiB)
          Interrupt:177 

..............
[root@smart202 ~]# ip link set eth1 up
[root@smart202 ~]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:1C:C4:18:B5:AC  
          inet addr:192.168.0.202  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::21c:c4ff:fe18:b5ac/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1
          RX packets:206 errors:0 dropped:0 overruns:0 frame:0
          TX packets:132 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:22652 (22.1 KiB)  TX bytes:14474 (14.1 KiB)
          Interrupt:177 

eth1      Link encap:Ethernet  HWaddr 00:1C:F0:D5:56:AA  
          inet addr:192.168.100.202  Bcast:192.168.100.255  Mask:255.255.255.0
          inet6 addr: fe80::21c:f0ff:fed5:56aa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1
          RX packets:160067 errors:0 dropped:0 overruns:0 frame:0
          TX packets:297262 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:15507892 (14.7 MiB)  TX bytes:85681680 (81.7 Mi
 [root@smart202 ~]# ip link set eth1 name wireless  //给网卡重启名字,关闭状态下
SIOCSIFNAME: Device or resource busy
[root@smart202 ~]# ip link set eth1 down
[root@smart202 ~]# ip link set eth1 name wireless
[root@smart202 ~]# ip link set eth1 up
SIOCGIFFLAGS: No such device
[root@smart202 ~]# ip link set wireless up
[root@smart202 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:1C:C4:18:B5:AC  
          inet addr:192.168.0.202  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::21c:c4ff:fe18:b5ac/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1
          RX packets:382 errors:0 dropped:0 overruns:0 frame:0
          TX packets:244 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:39503 (38.5 KiB)  TX bytes:27382 (26.7 KiB)
          Interrupt:177 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436 Metric:1
          RX packets:1635 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1635 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:3262921 (3.1 MiB)  TX bytes:3262921 (3.1 MiB)

wireless  Link encap:Ethernet  HWaddr 00:1C:F0:D5:56:AA  
          inet addr:192.168.100.202  Bcast:192.168.100.255  Mask:255.255.255.0
          inet6 addr: fe80::21c:f0ff:fed5:56aa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1
          RX packets:163199 errors:0 dropped:0 overruns:0 frame:0
          TX packets:301930 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:15702653 (14.9 MiB)  TX bytes:87469294 (83.4 MiB)
          Interrupt:193 

[root@smart202 ~]# 
+++++++++++++++++
ip address
 [root@smart202 ~]# ifconfig
。。。。。。。。
 eth1      Link encap:Ethernet  HWaddr 00:1C:F0:D5:56:AA  
          inet addr:192.168.100.202  Bcast:192.168.100.255  Mask:255.255.255.0
          inet6 addr: fe80::21c:f0ff:fed5:56aa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1
          RX packets:163989 errors:0 dropped:0 overruns:0 frame:0
          TX packets:303101 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:15751990 (15.0 MiB)  TX bytes:87916544 (83.8 MiB)
          Interrupt:193 

[root@smart202 ~]# 
[root@smart202 ~]# ip address add 1.1.1.1/24 broadcast +    //增加一个IP地址
> dev eth1 label eth1:eth1:1
或者 使用这条命令#ip address add 2.2.2.2/24 broadcast + dev eth0 label eth0:1
[root@smart202 ~]# ip address show eth1
3: eth1: mtu 1500 qdisc pfifo_fast qlen 1000
   link/ether 00:1c:f0:d5:56:aa brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.202/24 brd 192.168.100.255 scope global eth1
    inet 1.1.1.1/24 brd 1.1.1.255 scope global eth1:eth1:1  //同时还设置了它的广播地址
    inet6 fe80::21c:f0ff:fed5:56aa/64 scope link 
       valid_lft forever preferred_lft forever
[root@smart202 ~]# ping 1.1.1.2  //访问LAN中的其他主机
PING 1.1.1.2 (1.1.1.2) 56(84) bytes of data.
64 bytes from 1.1.1.2: icmp_seq=0 ttl=128 time=1.42 ms
64 bytes from 1.1.1.2: icmp_seq=1 ttl=128 time=0.155 ms
64 bytes from 1.1.1.2: icmp_seq=2 ttl=128 time=0.155 ms
64 bytes from 1.1.1.2: icmp_seq=3 ttl=128 time=0.150 ms

--- 1.1.1.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 0.150/0.470/1.421/0.549 ms, pipe 2
[root@smart202 ~]# ip address del 1.1.1.1/24 dev eth1   //删除掉刚才的设置
[root@smart202 ~]# ipconfig eth1
-bash: ipconfig: command not found
[root@smart202 ~]# ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:1C:F0:D5:56:AA  
          inet addr:192.168.100.202  Bcast:192.168.100.255  Mask:255.255.255.0
          inet6 addr: fe80::21c:f0ff:fed5:56aa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1
          RX packets:177663 errors:0 dropped:0 overruns:0 frame:0
          TX packets:323389 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:16605147 (15.8 MiB)  TX bytes:95691506 (91.2 MiB)
          Interrupt:193 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ip route
 [root@smart202 ~]# ip route show
192.168.100.0/24 dev eth1  proto kernel  scope link src 192.168.100.202 
192.168.0.0/24 dev eth0  proto kernel  scope link src 192.168.0.202 
[root@smart202 ~]# ip route add 1.1.1.1/24 dev eth1
RTNETLINK answers: Invalid argument
[root@smart202 ~]# ip route add 1.1.1.0/24 via 192.168.100.1 dev eth1 //添加静态路由
[root@smart202 ~]# ip route show
192.168.100.0/24 dev eth1  proto kernel  scope link src 192.168.100.202 
192.168.0.0/24 dev eth0  proto kernel  scope link src 192.168.0.202 
1.1.1.0/24 via 192.168.100.1 dev eth1 

[root@smart202 ~]# ip route add default via 192.168.100.1 dev eth1 //增加网关
[root@smart202 ~]# ip route show
192.168.100.0/24 dev eth1  proto kernel  scope link src 192.168.100.202 
192.168.0.0/24 dev eth0  proto kernel  scope link src 192.168.0.202 
1.1.1.0/24 via 192.168.100.1 dev eth1 
default via 192.168.100.1 dev eth1 
[root@smart202 ~]# ip route del 1.1.1.0/24