如何在私人networking上添加网关到debian系统

我的debian系统有IP地址192.168.111.111,我想configuration一个不在192.168.111.0networking上的默认网关。 作为第一步,我想添加一个路由,以便我可以从系统到达网关。 所以我运行这个命令(我认为将启用一个静态路由到单个主机),但我仍然无法ping网关:

# ip route add 5.6.71.166 dev eth0 # ping 5.6.71.166 PING 5.6.71.166 (5.6.71.166) 56(84) bytes of data. ^C --- 5.6.71.166 ping statistics --- 4 packets transmitted, 0 received, 100% packet loss, time 3023ms 

这是我的configuration:

 # netstat -rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 5.6.71.166 0.0.0.0 255.255.255.255 UH 0 0 0 eth0 192.168.111.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 # ifconfig eth0 eth0 Link encap:Ethernet HWaddr ca:eb:7c:e6:7e:98 inet addr:192.168.111.111 Bcast:192.168.111.255 Mask:255.255.255.0 inet6 addr: fe80::c8eb:7cff:fee6:7e98/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:45 errors:0 dropped:0 overruns:0 frame:0 TX packets:291 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:52454 (51.2 KiB) TX bytes:39433 (38.5 KiB) Interrupt:23 # cat /etc/network/interfaces # 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 internal network interface allow-hotplug eth0 iface eth0 inet static address 192.168.111.111 netmask 255.255.255.0 network 192.168.111.0 broadcast 192.168.111.255 # cat /proc/sys/net/ipv4/ip_forward 1 

我已经validation过,如果我在networking中使用IP地址,网关会响应ping,不幸的是,这不是一个选项,因为系统在该范围内不能有一个真实的IP地址(不是192.168.xx)。

你的默认网关是否知道回到你的机器的方式?

虽然你们两个(5.6.71.166和192.168.111.111)共享一个通用的layer2(“ethernet”),但都必须知道如何达到对方。 通常,它们共享一个通用的layer3(“ip subnet”),但是在这种情况下,gw必须有一条路由到192.168.111.111(/ 24?至less/ 32)到连接到公共l2的设备。

你有pipe理权限到你的gw吗?

我假设5.6.71.166是在不同的以太网域。 为了与不同的以太网域上的主机进行通信,主机必须使用网关才能到达那里。 您添加的路由指定5.6.71.166可以直接访问,这就是为什么它失败。 您需要提供一个适当的网关来使用。 假设192.168.111.1是本地networking上的网关:

 ip route add 5.6.71.166 via 192.168.111.1 

如果5.6.7.166网关位于同一个以太网域中,则它不知道如何将数据包路由回您的机器,或者数据包在某处被过滤。 网关在本地networking上需要192.168.111.0/24的路由,或者需要在网关的本地子网中添加一个IP地址到您的机器。

安装完成后,检查ARP是否在两台机器上工作:

 arp -n | grep 5.6.71.166 

你应该看到一个HW地址列表。 在网关上为你的机器的IP做同样的事情。 如果它仍然不起作用检查防火墙,并可能反向path过滤。

你可以添加另一个IP地址给eth0 iterface吗?

 ifconfig eth0:1 5.6.71.167 netmask xxxx up 

然后

 route add default gw 5.6.71.166 

你可以吗?