1. 程式人生 > >linux網絡配置命令(二)——ip

linux網絡配置命令(二)——ip

lag show 0.10 ack des 路由策略 node 主機 fix

ip命令

    查看/設置路由、設備、路由策略和渠道信息

格式

ip [ OPTIONS ] OBJECT { COMMAND | help }

OBJECT := { link | addr | addrlabel | route | rule | neigh | tunnel | maddr | mroute |

monitor } # 對象命令,類似於ip命令的子命令

  OPTIONS := { -V[ersion] | -s[tatistics] | -r[esolve] | -f[amily] { inet | inet6 | ipx |

dnet | link } | -o[neline] }

常見選項

-V 查看版本

-s 查看更詳細的內容

-f 強制使用指定的協議族

-4 指定使用IPv4協議

-6 指定使用IPv6協議

-0 不換行輸出信息

-r 使用主機的域名顯示主機

常用對象命令

ip link 設置、查看數據鏈路層信息

ip addr 查看設置ip信息

ip route 查看設置路由信息

查看對象命令使用方法

ip OBJECT help

示例

  1. 查看所有網卡的信息

[[email protected] ~]#ip a   #  查看所有網卡信息
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 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 ... 4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000 link/ether 00:0c:29:d3:79:32 brd ff:ff:ff:ff:ff:ff [[email protected]-pc ~]#ip a show eth2 # 查看網卡eth2的信息 4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000 link/ether 00:0c:29:d3:79:32 brd ff:ff:ff:ff:ff:ff

  2. 查看addr對象命令使用方法

[[email protected] ~]#ip route help   #  查看route對象命令的使用方法
Usage: ip route { list | flush } SELECTOR
       ip route get ADDRESS [ from ADDRESS iif STRING ]
                            [ oif STRING ]  [ tos TOS ]
       ip route { add | del | change | append | replace | monitor } ROUTE
SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ]
            [ table TABLE_ID ] [ proto RTPROTO ]
            [ type TYPE ] [ scope SCOPE ]
ROUTE := NODE_SPEC [ INFO_SPEC ]
NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ]
...

  3. 顯示路由信息

[[email protected] ~]#ip route
169.254.0.0/16 dev eth0  scope link  metric 1002 
169.254.0.0/16 dev eth1  scope link  metric 1003 
172.16.0.0/16 dev eth0  proto kernel  scope link  src 172.16.253.55 
55.0.0.0/8 dev eth1  proto kernel  scope link  src 55.0.0.55 
default via 55.0.0.1 dev eth1 

  4. 顯示下一跳或上一條的路由器的路由信息

[[email protected] ~]#ip neigh list
172.16.253.209 dev eth0 lladdr f0:76:1c:a9:8b:1b DELAY
172.16.0.1 dev eth0 lladdr f8:32:e4:73:bf:a4 STALE
172.16.252.15 dev eth0 lladdr 1c:cd:e5:3e:12:31 STALE
55.0.0.1 dev eth1  FAILED

  5. 分配ip地址信息

[[email protected] ~]#ip addr add 172.100.100.100/16 dev eth2      #  分配ip
[[email protected]-pc ~]#ip a show eth2                   #  查看eth2網卡信息
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 00:0c:29:d3:79:32 brd ff:ff:ff:ff:ff:ff
    inet 172.100.100.100/16 scope global eth2
[[email protected] ~]#ip addr del 172.100.100.100/16 dev eth2 # 刪除ip配置
[[email protected] ~]#ip addr flush eth2                  # 清楚eth2網卡上所有的ip配置

  6. 修改路由信息

[[email protected] ~]#ip route add 15.0.0.0/8 via 172.16.0.1          # 添加路由記錄
[[email protected]-pc ~]#ip route                          # 查看路由表  
169.254.0.0/16 dev eth0  scope link  metric 1002 
169.254.0.0/16 dev eth1  scope link  metric 1003 
172.16.0.0/16 dev eth0  proto kernel  scope link  src 172.16.253.55   
55.0.0.0/8 dev eth1  proto kernel  scope link  src 55.0.0.55        
15.0.0.0/8 via 172.16.0.1 dev eth0                      # 剛添加進去的
default via 55.0.0.1 dev eth1 
[[email protected]-pc ~]#ip route del 15.0.0.0/8                  # 刪除路由記錄
[[email protected]-pc ~]#route -n                          # 使用route命令查看路由記錄
Kernel IP routing table                       
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1003   0        0 eth1
172.16.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0
55.0.0.0        0.0.0.0         255.0.0.0       U     0      0        0 eth1
0.0.0.0         55.0.0.1        0.0.0.0         UG    0      0        0 eth1

linux網絡配置命令(二)——ip