我需要将我的 ubuntu pc 单网卡 ip 设置为 192.168.1.6 用于互联网,将 10.172.170.95 和 135.10.86.100 用于我的局域网以及通过我的 4 端口 DSL 调制解调器用于另一个网络。所以我这样定义。
除了添加最后两条路由(10.0.0.0/8 和 200.200.176.0/24)之外,一切都按定义工作,我犯了什么错误?
在 /etc/network/interfaces 文件中
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.6
netmask 255.255.255.0
gateway 192.168.1.1
在 /etc/rc.local 文件中
/sbin/ifconfig eth0:0 135.10.86.100 netmask 255.255.255.0
/sbin/ifconfig eth0:1 10.172.170.95 netmask 255.0.0.0.0
ip route add 10.0.0.0/8 via 10.172.170.6 src 10.172.170.95
ip route add 200.200.176.0/24 via 135.10.86.176 src 135.10.86.100
重启后,我发现
ifconfig 输出为,
eth0 Link encap:Ethernet HWaddr 00:11:82:87:12:4b
inet addr:192.168.1.6 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::221:85ff:fe96:441b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:760 errors:0 dropped:0 overruns:0 frame:0
TX packets:576 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:417620 (417.6 KB) TX bytes:93772 (93.7 KB)
Interrupt:26 Base address:0xa000
eth0:0 Link encap:Ethernet HWaddr 00:11:82:87:12:4b
inet addr:135.10.86.100 Bcast:135.10.86.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:26 Base address:0xa000
eth0:1 Link encap:Ethernet HWaddr 00:11:82:87:12:4b
inet addr:10.172.170.95 Bcast:10.255.255.255 Mask:255.0.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:26 Base address:0xa000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:240 (240.0 B) TX bytes:240 (240.0 B)
并将路由 -n 作为,
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
135.10.86.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
10.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 eth0