配置文件

配置文件

我有一台 Ubuntu 10.04 服务器,其配置如下:

eth0:192.168.10.XXX掩码255.255.255.0网关192.168.10.254
eth1:192.168.0.XXX掩码255.255.255.0网关192.168.0.3

eth0 用于传入和传出流量(内部网络服务器)
eth1 用于访问网络:192.168.51.0/24,网关为 192.168.0.1

当 eth1 关闭时,Web 服务器仍可访问。

当我想使 eth1 的状态变为 up 时,我使用以下命令:

$ sudo su
# ifconfig eth1 up
# route add -net 192.168.51.0 netmask 255.255.255.0 gw 192.168.0.1
# ping 192.168.51.XXX
[i've got contact]

# ip route add default via 192.168.10.254
# ping 192.168.51.XXX
[i've got contact]

但是当我想要访问网络服务器时,却无法联系。

有人可以给我一些建议,以便网络 .51 和网络服务器(网络 .10)可以访问吗?

答案1

我有解决办法!

我执行的命令是:

# route del -net 192.168.0.0 netmask 255.255.255.0 eth1

执行该命令后,我的:0 网络、10 网络和 51 网络均可访问。
我之前也编辑/etc/sysctl.conf并取消注释过net.ipv4.ip_forward=1,但我不确定这是否有必要。

我的配置:

配置文件

eth0      Link encap:Ethernet  HWaddr 00:0c:29:e0:03:9c  
          inet addr:192.168.10.2  Bcast:192.168.10.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fee0:39c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:53794 errors:0 dropped:0 overruns:0 frame:0
          TX packets:53916 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:6812117 (6.8 MB)  TX bytes:21573511 (21.5 MB)

eth0:1    Link encap:Ethernet  HWaddr 00:0c:29:e0:03:9c  
          inet addr:192.168.10.10  Bcast:192.168.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth1      Link encap:Ethernet  HWaddr 00:0c:29:e0:03:a6  
          inet addr:192.168.0.237  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fee0:3a6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:29845 errors:0 dropped:0 overruns:0 frame:0
          TX packets:469 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2555869 (2.5 MB)  TX bytes:42872 (42.8 KB)

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:8157 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8157 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:624350 (624.3 KB)  TX bytes:624350 (624.3 KB)

路线-n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.51.0    192.168.0.1     255.255.255.0   UG    0      0        0 eth1
192.168.10.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         192.168.10.254  0.0.0.0         UG    0      0        0 eth0
0.0.0.0         192.168.10.254  0.0.0.0         UG    100    0        0 eth0
0.0.0.0         192.168.10.254  0.0.0.0         UG    100    0        0 eth0

/etc/网络/接口

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static 
address 192.168.10.2
netmask 255.255.255.0
gateway 192.168.10.254

auto eth0:1
iface eth0:1 inet static
address 192.168.10.10
netmask 255.255.255.0
gateway 192.168.10.254

auto eth1
iface eth1 inet static
address 192.168.0.237
netmask 255.255.255.0
gateway 192.168.0.1
post-up route add -net 192.168.51.0 netmask 255.255.255.0 gw 192.168.0.1 

相关内容