无法使用 Ubuntu 17.4 作为互联网网关

无法使用 Ubuntu 17.4 作为互联网网关

我正在尝试设置一个 Ubuntu Desktop 17.04 虚拟机,作为隔离(非互联网连接)网络上其他虚拟机的路由器/网关。

我遵循了以下指示网址将 Ubuntu Desktop 设置为路由器(我认为这将允许我将 Ubuntu VM 用作 Windows VM 的互联网网关):

我要声明的是,我对 Linux/Ubuntu 完全是菜鸟。过去,我曾对 Linux/Unix 系统做过一些非常少的工作,但这种工作极其少见,而且已经持续了很多年。基本上,每次我看 Linux 系统时,都感觉像是第一次看一样。

我在 VMWare Player 12 上安装了带有 open-vm-tools-desktop 的 Ubuntu 17.04 桌面版。我安装了 2 个 NIC。两个都设置为 IPv4 上的手动。一个配置了具有互联网连接的静态 NAT IP,第二个配置了包含 Windows VM 的隔离 LAN 段上的静态 IP。我没有使用 IPv6。ifconfig 中 Ubuntu 桌面 VM 上的 NIC 名称为:

ens33  - Internet (eth1 in example from the above URL)

ens38  - LAN (eth0 in example from the above URL - the gateway is set to the same as the IP)

Ubuntu VM 确实具有互联网连接(通过 ping www.google.com、Firefox 连接和软件更新进行验证)。

除了通过 GUI 配置 Ubuntu NIC 之外,我还发出了以下命令(不包括以 ---- 开头的注释):

---- Enable IP forwarding commands:
sudo sh -c “echo 1 /proc/sys/net/ipv4/ip forward’’

我编辑了 /etc/sysctl.conf 并从下面一行删除了 # 注释符号并保存了文件:

# net.ipv4.ip forward=1

---- IP 伪装命令:

sudo iptables -t nat -A POSTROUTING -o ens33 -j MASQUERADE    
sudo iptables -A FORWARD -i ens33 -o ens38 -m state -–state RELATED,ESTABLISHED -j ACCEPT   
sudo iptables -A FORWARD -i ens38 -o ens33 -j ACCEPT

# iptables-save > /etc/iptables.rules

我可以从 Windows VM ping 通 Ubuntu 隔离的 LAN NIC IP,但是我无法从 Ubuntu VM 上连接互联网的 NIC 获得任何 ping 响应或访问互联网。

如果这很重要的话,我不会在 Ubuntu 上以任何形式使用 DHCP(我在隔离的 LAN 上确实有一个单独的 DHCP 服务器以及一些静态 IP 机器)。

有人能告诉我配置中我遗漏了什么吗(我希望可能是一些简单的东西......)?


我找到了另一个邮政来自尝试在此处进行设置的其他人。我注意到我的某些设置不同,但我不确定这是否是问题所在,或者是否与 Ubuntu 的不同版本有关?我的接口文件没有某些值,但不确定这些值是否是必需的,因为 NIC 是通过 GUI 配置的?路由中存在一些差异,但我猜这不是问题……IPtables 中存在一些差异,我猜这可能是问题所在?


我的配置信息如下:

ifconfig:

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.135.140  netmask 255.255.255.0  broadcast 192.168.135.255
        inet6 fe80::20c:29ff:fede:3b37  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:de:3b:37  txqueuelen 1000  (Ethernet)
        RX packets 3003  bytes 263817 (263.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 301  bytes 29406 (29.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens38: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.201.1  netmask 255.255.255.0  broadcast 192.168.201.255
        inet6 fe80::20c:29ff:fede:3b41  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:de:3b:41  txqueuelen 1000  (Ethernet)
        RX packets 96  bytes 9581 (9.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 246  bytes 25007 (25.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 354  bytes 26006 (26.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 354  bytes 26006 (26.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

接口:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

系统配置信息:

net.ipv4.ip_forward=1

路线:

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface    
0.0.0.0         192.168.135.2   0.0.0.0         UG        0 0          0 ens33    
0.0.0.0         192.168.201.1   0.0.0.0         UG        0 0          0 ens38    
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 ens33
192.168.135.0   0.0.0.0         255.255.255.0   U         0 0          0 ens33    
192.168.201.0   0.0.0.0         255.255.255.0   U         0 0          0 ens38

IP表:

Chain INPUT (policy ACCEPT)    
target     prot opt source               destination             

Chain FORWARD (policy ACCEPT)    
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination      

客户端 PC 配置(LAN NIC 上的 Windows 2012R2):

IP:     192.168.201.5   
Subnet:     255.255.255.0    
Gatewaay:   192.168.201.1

相关内容