並且擁有兩個對外IP,因此直覺的就會在 /etc/network/interface 內將兩個IP分別設定在兩張卡上....。
之後你就會發現,整台電腦都無法上網,因為你的主機有兩個Gateway,route路徑已經打架了。Orz
因此,要讓兩個ip都能共同存在,兩個Gateway的網路也都正常的設定,方法如下:
1. 建一個 在 /etc/netword/twoCard.sh 檔,內容為
#!/bin/bash2. 在 /etc/iproute2/rt_tables 內加入兩行
IF1=et0
IP1=203.72.20.2
NT1=203.72.20.0/24
GW1=203.72.20.251
IF2=eth1
IP2=163.27.7.2
NT2=163.27.7.0/24
GW2=163.27.7.250
DGW=${GW2}
ip route add ${NT1} dev ${IF1} src ${IP1} table T1
ip route add default via ${GW1} table T1
ip route add ${NT2} dev ${IF2} src ${IP2} table T2
ip route add default via ${GW2} table T2
ip route add ${NT1} dev ${IF1} src ${IP1}
ip route add ${NT2} dev ${IF2} src ${IP2}
ip route add default via ${DGW}
ip rule add from ${NT1} table T1
ip rule add from ${NT2} table T2
10 T13. 執行/etc/netword/twoCard.sh 網路就通了,神奇!
20 T2
補充: 讓每次網路重開機都執行此檔
修改 /etc/init.d/twocard
#! /bin/sh
### BEGIN INIT INFO
# Provides: single
# Required-Start: $local_fs $all killprocs
# Required-Stop:
# Default-Start: 1
# Default-Stop:
# Short-Description: executed by init(8) upon entering runlevel 1 (single).
### END INIT INFO
PATH=/sbin:/bin
do_start () {
log_action_msg "Two Card Mode ... go"
sh /etc/network/my_bi_ip.sh
}
case "$1" in
start)
do_start
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
# No-op
;;
*)
echo "Usage: $0 start|stop" >&2
exit 3
;;
esac
然後執行
sudo update-rc.d twocard defaults
這樣每次重開機就不用怕忘記要執行這個程式而無法連上網了
...
read more