iproute2常用命令

#常用命令
ip link show                             #显示链路
ip addr show                             #显示地址(或ifconfig)
ip route show                            #显示路由(route -n)
ip neigh show                            #显示arp表(ping 192.168.95.50,如果主机在同一局域网内,直接加到arp表)
ip neigh delete 192.168.95.50 dev eth0   #删除arp条目,条目仍然存在状态为stale,下次通信需要确认
ip rule show                             #显示缺省规则
ip route del default dev eth0            #删除接口路由
ip route show table local                #查看本地静态路由
ip route show table main                 #查看直连路由


#添加静态路由
ip route add 10.0.0.0/24 via 192.168.92.129
ip route add 10.10.10.10 via 192.168.92.129

ip route add 172.31.100.0/24 dev eno16777736
ip route add 172.32.0.2 dev eno16777736


#查看路由表
[root@localhost ~]# ip route show table main
default via 192.168.92.2 dev eno16777736  proto static  metric 1024 
10.0.0.0/24 via 192.168.92.129 dev eno16777736 
10.10.10.10 via 192.168.92.129 dev eno16777736 
172.31.100.0/24 dev eno16777736  scope link 
172.32.0.2 dev eno16777736  scope link 
192.168.92.0/24 dev eno16777736  proto kernel  scope link  src 192.168.92.129 


#删除
ip route del 10.0.0.0/24
ip route del 10.10.10.10

ip route del 172.31.100.0/24
ip route del 172.32.0.2

#再次查看路由表
[root@localhost ~]# ip route show table main
default via 192.168.92.2 dev eno16777736  proto static  metric 1024 
192.168.92.0/24 dev eno16777736  proto kernel  scope link  src 192.168.92.129


[root@localhost ~]# ip route show table local
broadcast 127.0.0.0 dev lo  proto kernel  scope link  src 127.0.0.1 
local 127.0.0.0/8 dev lo  proto kernel  scope host  src 127.0.0.1 
local 127.0.0.1 dev lo  proto kernel  scope host  src 127.0.0.1 
broadcast 127.255.255.255 dev lo  proto kernel  scope link  src 127.0.0.1 
broadcast 192.168.92.0 dev eno16777736  proto kernel  scope link  src 192.168.92.129 
local 192.168.92.129 dev eno16777736  proto kernel  scope host  src 192.168.92.129 
broadcast 192.168.92.255 dev eno16777736  proto kernel  scope link  src 192.168.92.129 






#添加网卡别名
ip addr add 192.168.0.11/24 dev eno16777736

#查看下网卡,别名没有产生,而是直接继承
[root@localhost ~]# ip addr show eno16777736
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:d0:a2:03 brd ff:ff:ff:ff:ff:ff
    inet 192.168.92.129/24 brd 192.168.92.255 scope global dynamic eno16777736
       valid_lft 1054sec preferred_lft 1054sec
    inet 192.168.0.11/24 scope global eno16777736
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed0:a203/64 scope link 
       valid_lft forever preferred_lft forever

       
#添加网卡别名并添加标记    label
ip addr add 192.168.1.2 label eno16777736:0 dev eno16777736


#查看下,多了eno16777736:0
ip addr show eno16777736
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:d0:a2:03 brd ff:ff:ff:ff:ff:ff
    inet 192.168.92.129/24 brd 192.168.92.255 scope global dynamic eno16777736
       valid_lft 1672sec preferred_lft 1672sec
    inet 192.168.0.11/24 scope global eno16777736
       valid_lft forever preferred_lft forever
    inet 192.168.1.2/32 scope global eno16777736:0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed0:a203/64 scope link 
       valid_lft forever preferred_lft forever
       
       
       
       
       
       
       
       
       
       
       
[root@localhost ~]# ip addr add 192.168.55.191/24 label eth0:1 dev eth0
[root@localhost ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:ce:58:47 brd ff:ff:ff:ff:ff:ff
    inet 192.168.55.143/24 brd 192.168.55.255 scope global eth0
    inet 192.168.55.191/24 scope global secondary eth0:1
    inet6 fe80::20c:29ff:fece:5847/64 scope link 
       valid_lft forever preferred_lft forever

 

posted @ 2015-06-29 22:40  ca0guo  阅读(6677)  评论(0编辑  收藏  举报