[root@smart Desktop]# ip route add help 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 ] [ table TABLE_ID ] [ proto RTPROTO ] [ scope SCOPE ] [ metric METRIC ] INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ]... NH := [ via ADDRESS ] [ dev STRING ] [ weight NUMBER ] NHFLAGS OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ rtt TIME ] [ rttvar TIME ] [reordering NUMBER ] [ window NUMBER] [ cwnd NUMBER ] [ initcwnd NUMBER ] [ ssthresh NUMBER ] [ realms REALM ] [ src ADDRESS ] [ rto_min TIME ] [ hoplimit NUMBER ] [ initrwnd NUMBER ] TYPE := [ unicast | local | broadcast | multicast | throw | unreachable | prohibit | blackhole | nat ] TABLE_ID := [ local | main | default | all | NUMBER ] SCOPE := [ host | link | global | NUMBER ] FLAGS := [ equalize ] MP_ALGO := { rr | drr | random | wrandom } NHFLAGS := [ onlink | pervasive ] RTPROTO := [ kernel | boot | static | NUMBER ] TIME := NUMBER[s|ms] [root@smart Desktop]# ip help Usage: ip [ OPTIONS ] OBJECT { COMMAND | help } ip [ -force ] -batch filename where OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable | tunnel | maddr | mroute | mrule | monitor | xfrm | token } OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] | -f[amily] { inet | inet6 | ipx | dnet | link } | -o[neline] | -t[imestamp] | -b[atch] [filename] | -rc[vbuf] [size]} [root@smart Desktop]# ip addr help Usage: ip addr {add|change|replace} IFADDR dev STRING [ LIFETIME ] [ CONFFLAG-LIST] ip addr del IFADDR dev STRING ip addr {show|flush} [ dev STRING ] [ scope SCOPE-ID ] [ to PREFIX ] [ FLAG-LIST ] [ label PATTERN ] IFADDR := PREFIX | ADDR peer PREFIX [ broadcast ADDR ] [ anycast ADDR ] [ label STRING ] [ scope SCOPE-ID ] SCOPE-ID := [ host | link | global | NUMBER ] FLAG-LIST := [ FLAG-LIST ] FLAG FLAG := [ permanent | dynamic | secondary | primary | tentative | deprecated | CONFFLAG-LIST ] CONFFLAG-LIST := [ CONFFLAG-LIST ] CONFFLAG CONFFLAG := [ home | nodad ] LIFETIME := [ valid_lft LFT ] [ preferred_lft LFT ] LFT := forever | SECONDS [root@smart Desktop]# ip addr add help Usage: ip addr {add|change|replace} IFADDR dev STRING [ LIFETIME ] [ CONFFLAG-LIST] ip addr del IFADDR dev STRING ip addr {show|flush} [ dev STRING ] [ scope SCOPE-ID ] [ to PREFIX ] [ FLAG-LIST ] [ label PATTERN ] IFADDR := PREFIX | ADDR peer PREFIX [ broadcast ADDR ] [ anycast ADDR ] [ label STRING ] [ scope SCOPE-ID ] SCOPE-ID := [ host | link | global | NUMBER ] FLAG-LIST := [ FLAG-LIST ] FLAG FLAG := [ permanent | dynamic | secondary | primary | tentative | deprecated | CONFFLAG-LIST ] CONFFLAG-LIST := [ CONFFLAG-LIST ] CONFFLAG CONFFLAG := [ home | nodad ] LIFETIME := [ valid_lft LFT ] [ preferred_lft LFT ] LFT := forever | SECONDS [root@smart Desktop]# ip addr add help Usage: ip addr {add|change|replace} IFADDR dev STRING [ LIFETIME ] [ CONFFLAG-LIST] ip addr del IFADDR dev STRING ip addr {show|flush} [ dev STRING ] [ scope SCOPE-ID ] [ to PREFIX ] [ FLAG-LIST ] [ label PATTERN ] IFADDR := PREFIX | ADDR peer PREFIX [ broadcast ADDR ] [ anycast ADDR ] [ label STRING ] [ scope SCOPE-ID ] SCOPE-ID := [ host | link | global | NUMBER ] FLAG-LIST := [ FLAG-LIST ] FLAG FLAG := [ permanent | dynamic | secondary | primary | tentative | deprecated | CONFFLAG-LIST ] CONFFLAG-LIST := [ CONFFLAG-LIST ] CONFFLAG CONFFLAG := [ home | nodad ] LIFETIME := [ valid_lft LFT ] [ preferred_lft LFT ] LFT := forever | SECONDS [root@smart Desktop]# ip link help Usage: ip link add link DEV [ name ] NAME [ txqueuelen PACKETS ] [ address LLADDR ] [ broadcast LLADDR ] [ mtu MTU ] type TYPE [ ARGS ] ip link delete DEV type TYPE [ ARGS ]
ip link set DEVICE [ { up | down } ] [ arp { on | off } ] [ dynamic { on | off } ] [ multicast { on | off } ] [ allmulticast { on | off } ] [ promisc { on | off } ] [ trailers { on | off } ] [ txqueuelen PACKETS ] [ name NEWNAME ] [ address LLADDR ] [ broadcast LLADDR ] [ mtu MTU ] [ netns PID ] [ alias NAME ] [ vf NUM [ mac LLADDR ] [ vlan VLANID [ qos VLAN-QOS ] ] [ rate TXRATE ] ] ip link show [ DEVICE ]
TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | can } [root@smart Desktop]#
[root@smart Desktop]# ip link help Usage: ip link add link DEV [ name ] NAME [ txqueuelen PACKETS ] [ address LLADDR ] [ broadcast LLADDR ] [ mtu MTU ] type TYPE [ ARGS ] ip link delete DEV type TYPE [ ARGS ]
ip link set DEVICE [ { up | down } ] [ arp { on | off } ] [ dynamic { on | off } ] [ multicast { on | off } ] [ allmulticast { on | off } ] [ promisc { on | off } ] [ trailers { on | off } ] [ txqueuelen PACKETS ] [ name NEWNAME ] [ address LLADDR ] [ broadcast LLADDR ] [ mtu MTU ] [ netns PID ] [ alias NAME ] [ vf NUM [ mac LLADDR ] [ vlan VLANID [ qos VLAN-QOS ] ] [ rate TXRATE ] ] ip link show [ DEVICE ]
TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | can }
[root@smart Desktop]# ip link 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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:45:5e:f7 brd ff:ff:ff:ff:ff:ff 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000 link/ether 00:0c:29:45:5e:01 brd ff:ff:ff:ff:ff:ff 5: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN link/ether 52:54:00:3a:b7:a4 brd ff:ff:ff:ff:ff:ff 6: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 500 link/ether 52:54:00:3a:b7:a4 brd ff:ff:ff:ff:ff:ff [root@smart Desktop]# ip link set eth1 up [root@smart Desktop]# ip link 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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:45:5e:f7 brd ff:ff:ff:ff:ff:ff 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:45:5e:01 brd ff:ff:ff:ff:ff:ff 5: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN link/ether 52:54:00:3a:b7:a4 brd ff:ff:ff:ff:ff:ff 6: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 500 link/ether 52:54:00:3a:b7:a4 brd ff:ff:ff:ff:ff:ff
ii.改变设备传输队列长度
ip link set dev eth0 txqueuelen 100
1 2 3 4 5 6 7 8 9 10 11 12
[root@smart Desktop]# ip link set dev eth0 txqueuelen 99 [root@smart Desktop]# ip link 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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 99 link/ether 00:01:4f:00:15:f1 brd ff:ff:ff:ff:ff:ff 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:45:5e:01 brd ff:ff:ff:ff:ff:ff 5: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN link/ether 52:54:00:3a:b7:a4 brd ff:ff:ff:ff:ff:ff 6: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 500 link/ether 52:54:00:3a:b7:a4 brd ff:ff:ff:ff:ff:ff
iii改变网络设备MTU(最大传输单元的值)
ip link set dev eth0 mtu 1000
1 2 3 4 5 6
[root@smart Desktop]# ip link set dev eth0 mtu 999 [root@smart Desktop]# ip link 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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 999 qdisc pfifo_fast state UP qlen 99 link/ether 00:01:4f:00:15:f1 brd ff:ff:ff:ff:ff:ff
iv.改变网络设备MAC地址
ip link set dev eth0 address 01:01:4f:00:15:f1
1 2 3 4 5 6
[root@smart Desktop]# ip link set dev eth0 address 01:01:4f:00:15:f1 [root@smart Desktop]# ip link 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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1000 qdisc pfifo_fast state UP qlen 99 link/ether 01:01:4f:00:15:f1 brd ff:ff:ff:ff:ff:ff
[root@smart Desktop]# ip route list 192.168.4.0/24 dev eth0 proto kernel scope link src 192.168.4.2 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.106 metric 1 192.168.42.0/24 dev eth1 proto kernel scope link src 192.168.42.128 metric 1 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 default via 192.168.1.1 dev eth0 proto static [root@smart Desktop]# ip route 192.168.4.0/24 dev eth0 proto kernel scope link src 192.168.4.2 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.106 metric 1 192.168.42.0/24 dev eth1 proto kernel scope link src 192.168.42.128 metric 1 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 default via 192.168.1.1 dev eth0 proto static [root@smart Desktop]# ip route flush "ip route flush" requires arguments. [root@smart Desktop]# ip route flush proto static [root@smart Desktop]# ip route 192.168.4.0/24 dev eth0 proto kernel scope link src 192.168.4.2 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.106 metric 1 192.168.42.0/24 dev eth1 proto kernel scope link src 192.168.42.128 metric 1 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
[root@smart Desktop]# ip route l default 192.168.2.0/24 dev eth0 scope link 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.106 metric 1 192.168.42.0/24 dev eth1 proto kernel scope link src 192.168.42.128 metric 1 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 default via 192.168.1.1 dev eth0 [root@smart Desktop]# ip route 192.168.2.0/24 dev eth0 scope link 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.106 metric 1 192.168.42.0/24 dev eth1 proto kernel scope link src 192.168.42.128 metric 1 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 default via 192.168.1.1 dev eth0 [root@smart Desktop]# ip route l t all 192.168.2.0/24 dev eth0 scope link 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.106 metric 1 192.168.42.0/24 dev eth1 proto kernel scope link src 192.168.42.128 metric 1 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 default via 192.168.1.1 dev eth0 192.168.4.0/24 via 192.168.1.1 dev eth0 table 5 broadcast 192.168.1.0 dev eth0 table local proto kernel scope link src 192.168.1.106 broadcast 127.255.255.255 dev lo table local proto kernel scope link src 127.0.0.1 broadcast 192.168.42.0 dev eth1 table local proto kernel scope link src 192.168.42.128 local 192.168.122.1 dev virbr0 table local proto kernel scope host src 192.168.122.1 local 192.168.42.128 dev eth1 table local proto kernel scope host src 192.168.42.128 broadcast 192.168.122.0 dev virbr0 table local proto kernel scope link src 192.168.122.1 local 192.168.1.106 dev eth0 table local proto kernel scope host src 192.168.1.106 broadcast 192.168.1.255 dev eth0 table local proto kernel scope link src 192.168.1.106 broadcast 192.168.42.255 dev eth1 table local proto kernel scope link src 192.168.42.128 broadcast 127.0.0.0 dev lo table local proto kernel scope link src 127.0.0.1 broadcast 192.168.122.255 dev virbr0 table local proto kernel scope link src 192.168.122.1 local 127.0.0.1 dev lo table local proto kernel scope host src 127.0.0.1 local 127.0.0.0/8 dev lo table local proto kernel scope host src 127.0.0.1 unreachable ::/96 dev lo metric 1024 error -101 mtu 16436 advmss 16376 hoplimit 0 unreachable ::ffff:0.0.0.0/96 dev lo metric 1024 error -101 mtu 16436 advmss 16376 hoplimit 0 unreachable 2002:a00::/24 dev lo metric 1024 error -101 mtu 16436 advmss 16376 hoplimit 0 unreachable 2002:7f00::/24 dev lo metric 1024 error -101 mtu 16436 advmss 16376 hoplimit 0 unreachable 2002:a9fe::/32 dev lo metric 1024 error -101 mtu 16436 advmss 16376 hoplimit 0 unreachable 2002:ac10::/28 dev lo metric 1024 error -101 mtu 16436 advmss 16376 hoplimit 0 unreachable 2002:c0a8::/32 dev lo metric 1024 error -101 mtu 16436 advmss 16376 hoplimit 0 unreachable 2002:e000::/19 dev lo metric 1024 error -101 mtu 16436 advmss 16376 hoplimit 0 unreachable 3ffe:ffff::/32 dev lo metric 1024 error -101 mtu 16436 advmss 16376 hoplimit 0 fe80::/64 dev virbr0 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 0 fe80::/64 dev eth1 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 0 unreachable default dev lo table unspec proto kernel metric -1 error -101 hoplimit 255 local ::1 via :: dev lo table local proto none metric 0 mtu 16436 advmss 16376 hoplimit 0 ff00::/8 dev virbr0 table local metric 256 mtu 1500 advmss 1440 hoplimit 0 ff00::/8 dev eth1 table local metric 256 mtu 1500 advmss 1440 hoplimit 0 unreachable default dev lo table unspec proto kernel metric -1 error -101 hoplimit 255
b.ip route get
ip route get ADDRESS [ from ADDRESS iif STRING ][ oif STRING ] [ tos TOS ]
[root@smart Desktop]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.4.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 1 0 0 eth0 192.168.42.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 [root@smart Desktop]# ip route get to 192.168.2.7 RTNETLINK answers: Network is unreachable [root@smart Desktop]# ip route ^C [root@smart Desktop]# route add default gw 192.168.1.1 [root@smart Desktop]# ip route get to 192.168.2.7 192.168.2.7 via 192.168.1.1 dev eth0 src 192.168.1.106 cache mtu 1000 advmss 960 hoplimit 64 [root@smart Desktop]# ip route get 192.168.1.7 from 192.168.1.106 192.168.1.7 from 192.168.1.106 dev eth0 cache mtu 1000 advmss 960 hoplimit 64 [root@smart Desktop]# ip route get 192.168.2.7 from 192.168.1.106 192.168.2.7 from 192.168.1.106 via 192.168.1.1 dev eth0 cache mtu 1000 advmss 960 hoplimit 64 [root@smart Desktop]# ip route get 192.168.2.7 to 192.168.1.106 local 192.168.1.106 dev lo src 192.168.1.106 cache <local> mtu 16436 advmss 16396 hoplimit 64
c.ip route add
ip route add 192.168.2.0/24 dev eth0 ip route add 192.168.3.0/24 via 192.168.1.1
ip route add 192.168.4.0/24 via 192.168.1.1 table 5
1 2 3 4 5 6 7 8 9 10 11 12
[root@smart Desktop]# ip route add 192.168.2.0/24 dev eth0 [root@smart Desktop]# [root@smart Desktop]# ip route add 192.168.3.0/24 via 192.168.1.1 [root@smart Desktop]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.3.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0 192.168.2.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 1 0 0 eth0 192.168.42.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
添加默认路由
ip route add default via 192.168.1.1
1 2 3 4 5 6 7 8 9 10
[root@smart Desktop]# ip route add default via 192.168.1.1 [root@smart Desktop]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.3.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0 192.168.2.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 1 0 0 eth0 192.168.42.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
[root@smart Desktop]# ip route add 192.168.5.0/24 via 192.168.1.1 [root@smart Desktop]# ip route del 192.168.5.0/24 dev eth0 [root@smart Desktop]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.2.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 1 0 0 eth0 192.168.42.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 eth1 0.0.0.0 192.168.42.1 0.0.0.0 UG 0 0 0 eth1 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 [root@smart Desktop]# ip route add 192.168.5.0/24 via 192.168.1.1 [root@smart Desktop]# ip route 192.168.5.0/24 via 192.168.1.1 dev eth0 192.168.2.0/24 dev eth0 scope link 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.106 metric 1 192.168.42.0/24 dev eth1 proto kernel scope link src 192.168.42.128 metric 1 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 default dev eth1 scope link default via 192.168.42.1 dev eth1 default via 192.168.1.1 dev eth0 [root@smart Desktop]# ip route del 192.168.5.0/24 via 192.168.1.1 dev eth0 [root@smart Desktop]#
[root@smart Desktop]# ip route 192.168.2.0/24 dev eth0 scope link 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.106 metric 1 192.168.42.0/24 dev eth1 proto kernel scope link src 192.168.42.128 metric 1 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 default dev eth1 scope link default via 192.168.42.1 dev eth1 default via 192.168.1.1 dev eth0 [root@smart Desktop]# ip route del default [root@smart Desktop]# ip route 192.168.2.0/24 dev eth0 scope link 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.106 metric 1 192.168.42.0/24 dev eth1 proto kernel scope link src 192.168.42.128 metric 1 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 default via 192.168.42.1 dev eth1 default via 192.168.1.1 dev eth0 [root@smart Desktop]# ip route del default [root@smart Desktop]# ip route 192.168.2.0/24 dev eth0 scope link 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.106 metric 1 192.168.42.0/24 dev eth1 proto kernel scope link src 192.168.42.128 metric 1 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 default via 192.168.1.1 dev eth0 [root@smart Desktop]#
[root@smart Desktop]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 192.168.2.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0 192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0 192.168.42.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 [root@smart Desktop]# ip route add 192.168.2.0/24 via 192.168.1.1 RTNETLINK answers: File exists [root@smart Desktop]# ip route append 192.168.2.0/24 via 192.168.1.1 RTNETLINK answers: File exists [root@smart Desktop]# ip route add 192.168.1.0/24 via 192.168.1.1 [root@smart Desktop]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 192.168.2.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0 192.168.1.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0 192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0 192.168.42.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 [root@smart Desktop]# ip route replace 192.168.2.0/24 via 192.168.2.1 [root@smart Desktop]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.2.0 192.168.2.1 255.255.255.0 UG 0 0 0 eth0 192.168.2.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0 192.168.1.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0 192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0 192.168.42.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 [root@smart Desktop]# ip route change 192.168.2.0/24 via 192.168.3.1 RTNETLINK answers: No such process [root@smart Desktop]# ip route change 192.168.1.0/24 via 192.168.2.1 RTNETLINK answers: No such process [root@smart Desktop]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.2.0 192.168.2.1 255.255.255.0 UG 0 0 0 eth0 192.168.2.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0 192.168.1.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0 192.168.1.0 * 255.255.255.0 U 1 0 0 eth0 192.168.42.0 * 255.255.255.0 U 1 0 0 eth1 192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0 default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 [root@smart Desktop]# ip route change^C [root@smart Desktop]# ip route replace 192.168.2.0/24 dev eth1 [root@smart Desktop]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 192.168.2.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0 192.168.1.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0 192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0 192.168.42.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 [root@smart Desktop]#
6.ip rule
ip rule [ list | add | del | flush ] SELECTOR ACTION
格式及用法
1 2 3 4 5 6 7 8 9
[root@smart Desktop]# ip rule help Usage: ip rule [ list | add | del | flush ] SELECTOR ACTION SELECTOR := [ not ] [ from PREFIX ] [ to PREFIX ] [ tos TOS ] [ fwmark FWMARK[/MASK] ] [ dev STRING ] [ pref NUMBER ] ACTION := [ table TABLE_ID ] [ prohibit | reject | unreachable ] [ realms [SRCREALM/]DSTREALM ] [ goto NUMBER ] TABLE_ID := [ local | main | default | NUMBER ]
[root@smart Desktop]# ip rule 0: from all lookup local 32766: from all lookup main 32767: from all lookup default [root@smart Desktop]# ip rule add from 192.168.7.0/24 table 5 [root@smart Desktop]# ip rule 0: from all lookup local 32765: from 192.168.7.0/24 lookup 5 32766: from all lookup main 32767: from all lookup default [root@smart Desktop]# ip rule add to 192.168.7.0/24 talbe 5 Error: argument "talbe" is wrong: Failed to parse rule type [root@smart Desktop]# ip rule add to 192.168.7.0/24 table 5 [root@smart Desktop]# ip rule 0: from all lookup local 32764: from all to 192.168.7.0/24 lookup 5 32765: from 192.168.7.0/24 lookup 5 32766: from all lookup main 32767: from all lookup default [root@smart Desktop]# ip rule add 192.168.1.0/24 reject Error: argument "192.168.1.0/24" is wrong: Failed to parse rule type [root@smart Desktop]# ip rule add from 192.168.1.0/24 reject Error: argument "reject" is wrong: Failed to parse rule type [root@smart Desktop]# ip rule add from 192.168.1.0/24 table 5 reject Error: argument "reject" is wrong: Failed to parse rule type [root@smart Desktop]# ip rule add from 192.168.1.0/24 table 5 [root@smart Desktop]# ip rule add from 192.168.5.0/24 table 5 [root@smart Desktop]# ip rule add from 192.168.5.0/24 table 5 reject Error: argument "reject" is wrong: Failed to parse rule type [root@smart Desktop]# ip rule add from 192.168.6.0/24 table 5 reject Error: argument "reject" is wrong: Failed to parse rule type [root@smart Desktop]# ip rule add from 192.168.6.0/24 table 5 unreachabel Error: argument "unreachabel" is wrong: Failed to parse rule type [root@smart Desktop]# ip rule add from 192.168.6.0/24 table 5 unreachable [root@smart Desktop]#
7.ip neigh
邻接ip情况
[root@smart Desktop]# ip neigh help
Usage: ip neigh { add | del | change | replace } { ADDR [ lladdr LLADDR ]
[ nud { permanent | noarp | stale | reachable } ]
| proxy ADDR } [ dev DEV ]
ip neigh {show|flush} [ to PREFIX ] [ dev DEV ] [ nud STATE ]
8.ip tunnel
ip隧道管理
[root@smart Desktop]# ip tunnel help
Usage: ip tunnel { add | change | del | show | prl } [ NAME ]
[ mode { ipip | gre | sit | isatap } ] [ remote ADDR ] [ local ADDR ]
[ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]
[ prl-default ADDR ] [ prl-nodefault ADDR ] [ prl-delete ADDR ]
[ ttl TTL ] [ tos TOS ] [ [no]pmtudisc ] [ dev PHYS_DEV ]
Where: NAME := STRING
ADDR := { IP_ADDRESS | any }
TOS := { NUMBER | inherit }
TTL := { 1..255 | inherit }
KEY := { DOTTED_QUAD | NUMBER }
[root@smart Desktop]# ip maddr help Usage: ip maddr [ add | del ] MULTIADDR dev STRING ip maddr show [ dev STRING ] [root@smart Desktop]# ip maddr 1: lo inet 224.0.0.1 inet6 ff02::1 2: eth0 link 01:00:5e:00:00:01 inet 224.0.0.1 3: eth1 link 33:33:ff:45:5e:01 link 33:33:00:00:00:01 link 01:00:5e:00:00:01 inet 224.0.0.1 inet6 ff02::1:ff45:5e01 inet6 ff02::1 5: virbr0 link 33:33:00:00:00:01 link 01:00:5e:00:00:01 inet 224.0.0.1 inet6 ff02::1 6: virbr0-nic link 33:33:00:00:00:01 inet6 ff02::1
10.ip monitor
ip monitor [ all | LISTofOBJECTS ]
用于监控ip情况
1 2 3 4 5
[root@smart Desktop]# ip monitor all [NEIGH]192.168.42.254 dev eth1 lladdr 00:50:56:fa:5f:cf REACHABLE [NEIGH]192.168.42.254 dev eth1 lladdr 00:50:56:fa:5f:cf STALE [ROUTE]192.168.5.0/24 via 192.168.1.1 dev eth0