Chinaunix首页 | 论坛 | 博客
  • 博客访问: 632729
  • 博文数量: 151
  • 博客积分: 4010
  • 博客等级: 上校
  • 技术积分: 1664
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-13 16:37
文章分类

全部博文(151)

文章存档

2010年(16)

2009年(135)

我的朋友

分类: LINUX

2010-01-11 15:29:50

服务器有两个网卡eth0和eth2,都可访问internet.
[root@layer7 sched]# ip add ls
1: lo: mtu 16436 qdisc noqueue
    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: mtu 1500 qdisc htb qlen 1000
    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: mtu 1500 qdisc htb qlen 1000
    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: mtu 1500 qdisc pfifo_fast qlen 1000
    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: mtu 1480 qdisc noop
    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

阅读(3228) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~