我不是专家,但经过一些研究,我可以解决类似的问题。我有一台托管 Debian 服务器的 Mac。我在 Mac 的接口 en0 上使用了桥接适配器。
1) 我的 Mac 在 192.168.10.101 上运行。我知道,因为我运行命令:
ifconfig -a
接口en0显示IP
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 6c:40:08:98:72:4c
inet6 fe80::6e40:8ff:fe98:724c%en0 prefixlen 64 scopeid 0x4
inet 192.168.10.101 netmask 0xffffff00 broadcast 192.168.10.255
2) 在我的 Mac 上运行 netstat 命令:
netstat -nr
Internet:
Destination Gateway Flags Refs Use Netif Expire
default 192.168.10.1 UGSc 296 142 en0
我看到 Mac 网关在 192.168.10.1
3) Mac 和 Debian 必须与网关在同一网段,我的意思是 192.168.10.xxx。所以我决定我的 Debian 必须在静态 IP 192.168.10.115 上运行。
我在我的 Debian 服务器上编辑了 /etc/network/interfaces 文件,使其看起来像这样:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet static
address 192.168.10.115
netmask 255.255.255.0
gateway 192.168.10.1
dns-nameservers 8.8.8.8 192.168.10.1
然后我从我的 Mac 上 ping 并从我的 Debian 上 ping,他们回答了 Ok。我也可以从 Debian 访问互联网,因为我的默认网关与我的 Mac 相同。
root@debian64:/home/myuser# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default TEW-711BR 0.0.0.0 UG 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
我希望它有所帮助,如果有人有更好的解释,我想学习。