Chinaunix首页 | 论坛 | 博客
  • 博客访问: 672137
  • 博文数量: 176
  • 博客积分: 4791
  • 博客等级: 上校
  • 技术积分: 1921
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-24 18:47
个人简介

it江湖漂,怎能不挨刀;一朝机器当,看你怎么着!

文章分类

全部博文(176)

文章存档

2014年(2)

2012年(17)

2011年(27)

2010年(18)

2009年(6)

2008年(21)

2007年(43)

2006年(42)

分类: LINUX

2006-05-25 16:02:28

環境: 兩條對外網路, 兩個 ATU-R 均接到 Hub, 電腦接 Hub

IP1 100.100.100.100/24 Gateway 100.100.100.254
IP2 200.200.200.200/24 Gateway 200.200.200.254

ifconfig eth0 100.100.100.100 netmask 255.255.255.0
ifconfig eth0:0 200.200.200.200 netmask 255.255.255.0

由於 default gateway 只能設一個, 所以會有其中一個 IP 不通

必需用 ip route2 來解決這個問題
kernel option 中的 IP: policy routing 必需勾選(CONFIG_IP_MULTIPLE_TABLES)
否則在使用 ip rule 時會出現如下錯誤訊息
# ip rule list
RTNETLINK error: Invalid argument
dump terminated

先在 /etc/iproute2/rt_tables 下建兩個 table
echo "100 line1" >> /etc/iproute2/rt_tables
echo "200 line2" >> /etc/iproute2/rt_tables

# 設定 line1 的 gateway
ip route add default via 100.100.100.254 table line1
# 設定 line2 的 gateway
ip route add default via 200.200.200.254 table line2
# 指定從 100.100.100.100 進來的連線走 rule line1
ip rule add from 100.100.100.100 table line1
# 指定從 200.200.200.200 進來的連線走 rule line1
ip rule add from 200.200.200.200 table line2

設完後, 從外面連兩個 IP 都可以通

連外負載平衡
kernel option 中的 IP: equal cost multipath 必需勾選(CONFIG_IP_ROUTE_MULTIPATH)
指定 multipath
ip route add default scope global nexthop via 100.100.100.254 dev eth0 weight 1 \
nexthop via 200.200.200.254 dev eth0 weight 1
設完後就達成 line1 line2 路由平衡, 可以調整 weight 參數來決定 line1 或 line2 的比重
ip route list 會看到 default 如下
default
nexthop via 100.100.100.254 dev eth0 weight 1
nexthop via 200.200.200.254 dev eth0 weight 1

阅读(1255) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:数据库恢复实例

给主人留下些什么吧!~~