# ip link1: 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> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:0c:29:3b:9c:6f brd ff:ff:ff:ff:ff:ff
# ip link show dev eth02: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:0c:29:3b:9c:6f brd ff:ff:ff:ff:ff:ff
显示IP地址
123456789
# ip addr1: 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> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:0c:29:3b:9c:6f brd ff:ff:ff:ff:ff:ff
inet 192.168.0.10/24 brd 192.168.0.255 scope global eth0
显示路由ip route [类似route -n]
12345678910
# ip route | column -t192.168.0.0/24 dev eth1 scope link
10.2.0.0/16 dev eth2 proto kernel scope link src 10.2.0.111
default via 10.2.255.254 dev eth2
# ip route del 192.168.0.0/24 dev eth1# ip route add 192.168.0.0/24 dev eth1# ip route del via 10.2.255.254 //删除默认路由# ip route add via 10.2.255.254 //增加默认路由# ip route add 192.168.1.0/24 via 192.168.0.1 //增加静态路由,192.168.0.1为下一跳地址# ip route del 192.168.1.0/24 via 192.168.0.1 //删除静态路由
显示arp信息ip neigh [可以取代arp -n],删除则是ip neigh del IP地址 dev 设备名
# ip rule0: from all lookup local 32766: from all lookup main
32767: from all lookup default
上面列出了规则的优先顺序。ip route命令默认显示的就是main表。ip route show table all显示所有规则中的表
12345
# ip route list table localbroadcast 192.168.0.255 dev eth0 proto kernel scope link src 192.168.0.10
broadcast 10.2.0.0 dev eth1 proto kernel scope link src 10.2.0.217
broadcast 127.255.255.255 dev lo proto kernel scope link src 127.0.0.1
... ...
[ahu@home ahu]$ ip route list table localbroadcast 127.255.255.255 dev lo proto kernel scope link src 127.0.0.1
local 10.0.0.1 dev eth0 proto kernel scope host src 10.0.0.1
broadcast 10.0.0.0 dev eth0 proto kernel scope link src 10.0.0.1
local 212.64.94.251 dev ppp0 proto kernel scope host src 212.64.94.251
broadcast 10.255.255.255 dev eth0 proto kernel scope link src 10.0.0.1
broadcast 127.0.0.0 dev lo proto kernel scope link src 127.0.0.1
local 212.64.78.148 dev ppp2 proto kernel scope host src 212.64.78.148
local 127.0.0.1 dev lo proto kernel scope host src 127.0.0.1
local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
让我们看看“main”路由表:
123456
[ahu@home ahu]$ ip route list table main
195.96.98.253 dev ppp2 proto kernel scope link src 212.64.78.148
212.64.94.1 dev ppp0 proto kernel scope link src 212.64.94.251
10.0.0.0/8 dev eth0 proto kernel scope link src 10.0.0.1
127.0.0.0/8 dev lo scope link
default via 212.64.94.1 dev ppp0
# echo 200 John >> /etc/iproute2/rt_tables# ip rule add from 10.0.0.10 table John# ip rule0: from all lookup local 32765: from 10.0.0.10 lookup John
32766: from all lookup main
32767: from all lookup default
现在,剩下的事情就是为 John 的路由表创建路由项了。别忘了刷新路由缓存:
12
# ip route add default via 195.96.98.253 dev ppp2 table John# ip route flush cache
总结主要是以下几步:
echo 200 John >> /etc/iproute2/rt_tables #方便表示,把规则名字和数字对应加入到/etc/iproute2/rt_tables文件
ip rule add from 10.0.0.10 table John #新增规则
ip route add default via 195.96.98.253 dev ppp2 table John #规则中添加路由表