我对这个问题有很大的困惑。
我希望能够通过我的 WIFI 接口 ping 并访问 TFTP(wlan0)通过我的有线接口(eth0)
pc1_eth->LTdhcps2_eth0->LTdhcps2_wlan0->pc2_wlan
反之亦然
pc2_wlan->LTdhcps2_wlan0->LTdhcps2_eth0->pc1_eth
起初我以为这会很简单,因为我认为我只需要用我的 wlan0 的 IP 设置我的 eth0 的网关。
我错了,我无法做到这一点。
让痛苦开始吧..
1)我认为 pc1 和 pc2 的配置不合适,因为它只涉及 LTdhcps2 接口,对吗?
服务器 LTdhcps2
Eth0
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 primary network interface
#allow-hotplug eth0
#iface eth0 inet dhcp
auto eth0
iface eth0 inet static
address 192.168.2.10
netmask 255.255.255.0
WLAN0
DHCP 是否由网络管理器配置(我不知道如何使用 wpa_supplicant 进行配置)
启动服务后
service network-manager start
service networking start
这是结果
[root@LTdhcps2:~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:1e:c9:24:c9:d1
inet addr:192.168.2.10 Bcast:192.168.2.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:44 Base address:0xc000
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:20 errors:0 dropped:0 overruns:0 frame:0
TX packets:20 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1348 (1.3 KiB) TX bytes:1348 (1.3 KiB)
wlan0 Link encap:Ethernet HWaddr 00:24:2b:c7:74:7e
inet addr:10.0.2.218 Bcast:10.0.3.255 Mask:255.255.252.0
inet6 addr: fe80::224:2bff:fec7:747e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:24154 errors:0 dropped:0 overruns:0 frame:37468
TX packets:677 errors:8 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1670308 (1.5 MiB) TX bytes:140171 (136.8 KiB)
Interrupt:19
[root@LTdhcps2:~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.1.2 0.0.0.0 UG 0 0 0 wlan0
10.0.0.0 0.0.0.0 255.255.252.0 U 0 0 0 wlan0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[root@LTdhcps2:~]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.0.1.2 0.0.0.0 UG 0 0 0 wlan0
10.0.0.0 0.0.0.0 255.255.252.0 U 0 0 0 wlan0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
我已尝试做过的事。
[root@LTdhcps2:~]# route add -net 10.0.0.0 gw 10.0.2.218 dev eth0
SIOCADDRT: Invalid argument
[root@LTdhcps2:~]#
奇怪的错误,毫无意义=|我在谷歌上搜索并找到了这篇文章:http://www.adminsehow.com/2011/09/gateway-on-a-different-subnet-on-linux/
它说你必须添加一个具有所需网关 IP 的主机,因为网关位于不同的子网中。
[root@LTdhcps2:~]# route add -host 10.0.2.218/32 dev eth0
[root@LTdhcps2:~]# route add default gw 10.0.2.218
(如果我将 dev eth0 放在第二个命令的末尾)它会给出 SIOCADDRT:没有这样的过程错误。
结果:
[root@LTdhcps2:~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 10.0.2.218 0.0.0.0 UG 0 0 0 wlan0
default 10.0.1.2 0.0.0.0 UG 0 0 0 wlan0
10.0.0.0 * 255.255.252.0 U 0 0 0 wlan0
10.0.2.218 * 255.255.255.255 UH 0 0 0 eth0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0
[root@LTdhcps2:~]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.0.2.218 0.0.0.0 UG 0 0 0 wlan0
0.0.0.0 10.0.1.2 0.0.0.0 UG 0 0 0 wlan0
10.0.0.0 0.0.0.0 255.255.252.0 U 0 0 0 wlan0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
但我无法使用 eth0 接口或其网关 (10.0.1.2) ping/traceroute wlan0
[root@LTdhcps2:~]# ping -I eth0 10.0.2.218
PING 10.0.2.218 (10.0.2.218) from 192.168.2.10 eth0: 56(84) bytes of data.
From 192.168.2.10 icmp_seq=1 Destination Host Unreachable
From 192.168.2.10 icmp_seq=2 Destination Host Unreachable
[root@LTdhcps2:~]# ping -I eth0 10.0.1.2
PING 10.0.1.2 (10.0.1.2) from 192.168.2.10 eth0: 56(84) bytes of data.
From 192.168.2.10 icmp_seq=1 Destination Host Unreachable
From 192.168.2.10 icmp_seq=2 Destination Host Unreachable
[root@LTdhcps2:~]# traceroute -i eth0 10.0.2.218
traceroute to 10.0.2.218 (10.0.2.218), 30 hops max, 60 byte packets
1 * * *
2 * * *
3 * * *
4 * * *
抱歉,帖子太长,而且英语不好。我在圣周遇到了这个问题=|
答案1
我解答了这个问题。
ping -I 接口或 traceroute -i 接口
它们不是检查其是否工作的方法,您不需要指定接口,因为如果您这样做,内核就不会使用路由表(我猜)。