close
核心
必備
CONFIG_NETLINK=y 這個選項是 Kernel/User netlink socket
CONFIG_RTNETLINK=y Routing messages
CONFIG_INET=y TCP/IP networking
CONFIG_IP_ADVANCED_ROUTER=y IP: advanced router
CONFIG_IP_MULTIPLE_TABLES=y IP: policy routing
CONFIG_IP_ROUTE_MULTIPATH=y IP: equal cost multipath
選用:
CONFIG_IP_ROUTE_LARGE_TABLES=y
一般來講 IP: large routing tables 也會勾選, 一方面 routing zones 可以大於 64 筆, 這些資料存在 hash 資料結構中, 也可以加速 "the routing process".
eth0 是內部網路, 範圍是 10.0.0.0/255.255.255.0
eth1 其中一家 ISP, IP 是 1.1.1.1, 閘道器(gateway)是 1.1.1.253
eth2 另外一家 ISP, IP 是 2.2.2.2, 閘道器(gateway)是 2.2.2.253
# 列出所有的 rule
ip rule list
# table 後的 "10" 是 table identifer, 為數字.
# 註: 可用英文代稱取代請看 /etc/iproute2/rt_tables
#
# table 10 是給在 gateway 後面的內部網路使用, 10.0.0.x 是 LAN 使用的 IP.
#
# pref 後面指定的 "10" 是 priority. 為 policy routing database 搜尋的次序
ip rule add pref 10 to 10.0.0.0/24 table 10
ip route add 10.0.0.0/24 table 10 dev eth1
# table 20 給 ISP #1, IP 1.1.1.1, gateway 1.1.1.253
# pref 後面指定的 "20" 是 priority. 為 policy routing database 搜尋的次序
ip rule add pref 20 from 1.1.1.1 table 20
ip route add default table 20 via 1.1.1.253
# table 30 is for ISP #2, IP 2.2.2.2, gateway 2.2.2.253
ip rule add pref 20 from 2.2.2.2 table 30
ip route add default table 30 via 2.2.2.253
# 列出所有的 rule
ip rule list
# 列出 table 10 的 rule
ip route list table 10
# 列出 table 20 的 rule
ip route list table 20
# If your ISP's have servers that authenticate by originating IP address,
# (e.g. SMTP or NNTP servers) you will want to explicitly list them here.
# 這裡是靜態的 routing table 設定. 如果你的 ISP 有提供某些網路服務, 必須該
# ISP 的 IP 才能使用, 那麼你會想將它設定在這裡
# (e.g. Proxy, SMTP or NNTP Server)
ip route add 1.1.1.0/24 dev eth1
ip route add 2.2.2.0/24 dev eth2
# 如果上面所有的 routing table 都沒有吻合, 那麼封包會走 default route
# 這裡使用 "ECMP" 來選擇上游路由器.
# "ip route repleace" 是用來取代原本的 default routi.
ip route replace default nexthop via 1.1.1.253 dev eth1 \
nexthop via 2.2.253 dev eth2
# 如果你想加上權重, 是這樣使用的. 請依據你的線路網路頻寬
# 頻寬越大, 請把 weight 加大.
#ip route replace default nexthop via 1.1.1.253 dev eth1 weight 1 \
# nexthop via 2.2.253 dev eth2 weight 3
# Make it all happen. IMPORTANT! The above commands do NOT
# flush the route cache
ip route flush cache
http://www.study-area.org/tips/m_routing.htm
全站熱搜