全部博文(151)
分类: LINUX
2010-01-11 15:29:50
服务器有两个网卡eth0和eth2,都可访问internet.
[root@layer7 sched]# ip add ls
1: lo:
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:
link/ether 00:0c:29:6c:d4:00 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.212/24 brd 192.168.0.255 scope global eth0
inet6 fe80::20c:29ff:fe6c:d400/64 scope link
valid_lft forever preferred_lft forever
3: eth1:
link/ether 00:0c:29:6c:d4:0a brd ff:ff:ff:ff:ff:ff
inet 192.168.168.212/24 brd 192.168.168.255 scope global eth1
inet6 fe80::20c:29ff:fe6c:d40a/64 scope link
valid_lft forever preferred_lft forever
4: eth2:
link/ether 00:0c:29:6c:d4:14 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.212/24 brd 10.0.0.255 scope global eth2
inet6 fe80::20c:29ff:fe6c:d414/64 scope link
valid_lft forever preferred_lft forever
5: sit0:
link/sit 0.0.0.0 brd 0.0.0.0
为内部192.168.168.0/24这一网段走192.168.0.1这一网关上网.
[root@layer7 sched]#echo 200 www >> /etc/iproute2/rt_tables
[root@layer7 sched]#ip rule add from 192.168.168.0/24 table www
[root@layer7 sched]# ip rule ls
0: from all lookup 255
32765: from 192.168.168.0/24 lookup www
32766: from all lookup main
32767: from all lookup default
现在,为 www 的路由表创建路由项了。别忘了刷新路由缓存:
[root@layer7 sched]# ip route add default via 192.168.0.1 dev eth0 table www
[root@layer7 sched]# ip route flush cache
---------------
[root@layer7 sched]# ip route ls table main
10.0.0.0/24 dev eth2 proto kernel scope link src 10.0.0.212
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.212
192.168.168.0/24 dev eth1 proto kernel scope link src 192.168.168.212
169.254.0.0/16 dev eth0 scope link
--------
[root@layer7 sched]# ip route ls table local
local 192.168.168.212 dev eth1 proto kernel scope host src 192.168.168.212
broadcast 192.168.0.255 dev eth0 proto kernel scope link src 192.168.0.212
broadcast 127.255.255.255 dev lo proto kernel scope link src 127.0.0.1
broadcast 192.168.168.0 dev eth1 proto kernel scope link src 192.168.168.212
broadcast 10.0.0.0 dev eth2 proto kernel scope link src 10.0.0.212
local 10.0.0.212 dev eth2 proto kernel scope host src 10.0.0.212
broadcast 192.168.0.0 dev eth0 proto kernel scope link src 192.168.0.212
broadcast 192.168.168.255 dev eth1 proto kernel scope link src 192.168.168.212
local 192.168.0.212 dev eth0 proto kernel scope host src 192.168.0.212
broadcast 10.0.0.255 dev eth2 proto kernel scope link src 10.0.0.212
broadcast 127.0.0.0 dev lo proto kernel scope link src 127.0.0.1
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