我目前正在创建基于 Ubuntu Server 的网络。
它在 VirtualBox 中作为 VM 实现,如下所示:
- Ubuntu 服务器 - 3 个网络接口。第 1 个 -
enp0s3
互联网连接。第 2 个enp0s9
-room_two
VBox 内部网络。 - ArchLinux 工作站 - 1 个网络接口,,
enp0s3
连接到room_two
。
我想要实现的目标:服务器路由从enp0s3
到room_two
内部网络。
我已经做了什么:
# /etc/netplan/50-cloud-init.yaml
network:
ethernets:
enp0s3:
addresses: []
dhcp4: true
enp0s8:
addresses: [192.168.1.1/16]
dhcp4: false
version: 2
双接口路由器的 Shorewall 设置。
/etc/shorewall/zones
#ZONE TYPE OPTIONS IN OUT
# OPTIONS OPTIONS
fw firewall
net ipv4
loc ipv4
/etc/shorewall/rules
#ACTION SOURCE DEST PROTO DEST SOURCE ORIGINAL RATE USER/ MARK CONNLIMIT TIME HEADERS SWITCH HELPER
# PORT PORT(S) DEST LIMIT GROUP
?SECTION ALL
?SECTION ESTABLISHED
?SECTION RELATED
?SECTION INVALID
?SECTION UNTRACKED
?SECTION NEW
# Don't allow connection pickup from the net
#
Invalid(DROP) net all tcp
#
# Accept DNS connections from the firewall to the network
#
DNS(ACCEPT) $FW net
DNS(ACCEPT) loc $FW
#
# Accept SSH connections from the local network for administration
#
SSH(ACCEPT) loc $FW
SSH(ACCEPT) net $FW
#
# Allow Ping from the local network
#
Ping(ACCEPT) loc $FW
Ping(ACCEPT) $FW loc
#
# Drop Ping from the "bad" net zone.. and prevent your log from being flooded..
#
Ping(DROP) net $FW
ACCEPT $FW loc icmp
ACCEPT $FW net icmp
#
/etc/shorewall/policy
#SOURCE DEST POLICY LOGLEVEL RATE CONNLIMIT
$FW net ACCEPT
loc net ACCEPT
net all DROP $LOG_LEVEL
# THE FOLOWING POLICY MUST BE LAST
all all REJECT $LOG_LEVEL
/etc/shorewall/interfaces
#ZONE INTERFACE OPTIONS
net NET_IF dhcp,tcpflags,nosmurfs,routefilter,logmartians,sourceroute=0,physical=enp0s3
loc LOC_IF dhcp,tcpflags,nosmurfs,routefilter,logmartians,physical=enp0s8
/etc/shorewall/snat
# Rules generated from masq file /home/teastep/shorewall/trunk/Shorewall/Samples/two-interfaces/masq by Shorewall 5.0.13-RC1 - Sat Oct 15 11:41:40 PDT 2016
#
MASQUERADE 10.0.0.0/8,\
169.254.0.0/16,\
172.16.0.0/12,\
192.168.0.0/16 NET_IF
我的 Ubuntu 服务器运行良好,DNS 请求已缓存,我可以访问互联网。在我的 ArchLinux 客户端上,我从 DHCP 服务器获取 IP 地址,当我“ping google.com”时,我获取了正确的 IP 地址,但数据包丢失率为 100%。我应该在哪里查找信息以及查找哪种信息?我可能做错了什么?关于 Shorewall + Netplan 设置的资源并不多,因为后者相当新。
答案1
我找到了解决方案,位于/etc/sysctl.conf
:
net.ipv4.ip_forward=1
现在一切都运行正常!