我的 Linux 作为网关设置有问题。不知道我这里做错了什么。
预期结果:
- 计算机根据 DHCP 保留的 IP 地址转发服务。
- 我可以从互联网访问服务器(我有 DDNS)
网络架构:
- 互联网
- 路由器(附带 DDNS)
- Linux Box - (有线计算机命名网关) - IP 192.168.1.161 (enp9s0 上的外部) 192.168.99.1 (enp7s5 上的内部)
- 交换机-IP 192.168.99.100
- 多台计算机 - (有线) - IP 192.168.99.102、192.168.99.103、192.168.99.104、192.168.99.105
有效的方法:
- DHCP 提供保留 IP 地址
- 计算机内部有互联网
- 我可以从与 enp9s0 位于同一网络的计算机通过 ssh 进入网关(不是通过互联网)
- DDNS 将信息正确转发给路由器
问题:
- 端口不转发到内部计算机
- 我无法从互联网访问任何内容
附加信息:这是一个共享网络。同一网络中将有 Windows 和 Linux 机器。
IP表:
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
# enp9s0 is WAN interface, enp7s5 is LAN interface
-A POSTROUTING -o enp9s0 -j MASQUERADE
# NAT pinhole: HTTP from WAN to LAN
-A PREROUTING -p tcp -m tcp -i enp9s0 --dport 80 -j DNAT --to-destination 192.168.99.100:80
-A PREROUTING -p tcp -m tcp -i enp9s0 --dport 8086 -j DNAT --to-destination 192.168.99.102:8$
-A PREROUTING -p tcp -m tcp -i enp9s0 --dport 7990 -j DNAT --to-destination 192.168.99.103:7$
-A PREROUTING -p tcp -m tcp -i enp9s0 --dport 8080 -j DNAT --to-destination 192.168.99.104:8$
-A PREROUTING -p tcp -m tcp -i enp9s0 --dport 8090 -j DNAT --to-destination 192.168.99.104:8$
-A PREROUTING -p tcp -m tcp -i enp9s0 --dport 8085 -j DNAT --to-destination 192.168.99.105:8$
-A PREROUTING -p tcp -m tcp -i enp9s0 --dport 9002 -j DNAT --to-destination 192.168.99.102:22
-A PREROUTING -p tcp -m tcp -i enp9s0 --dport 9003 -j DNAT --to-destination 192.168.99.103:22
-A PREROUTING -p tcp -m tcp -i enp9s0 --dport 9014 -j DNAT --to-destination 192.168.99.104:9$
-A PREROUTING -p tcp -m tcp -i enp9s0 --dport 9005 -j DNAT --to-destination 192.168.99.105:22
COMMIT
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
# Service rules
# basic global accept rules - ICMP, loopback, traceroute, established all accepted
-A INPUT -s 127.0.0.0/8 -d 127.0.0.0/8 -i lo -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -m state --state ESTABLISHED -j ACCEPT
# enable traceroute rejections to get sent out
#-A INPUT -p udp -m udp --dport 33434:33523 -j REJECT --reject-with icmp-port-unreachable
# DNS - accept from LAN
-A INPUT -i enp7s5 -p tcp --dport 53 -j ACCEPT
-A INPUT -i enp7s5 -p udp --dport 53 -j ACCEPT
# SSH - accept from LAN
-A INPUT -i enp7s5 -p tcp --dport 9001 -j ACCEPT
#SSH - accept from wan
-A INPUT -i enp9s0 -p tcp --dport 9001 -j ACCEPT
# DHCP client requests - accept from LAN
-A INPUT -i enp7s5 -p udp --dport 67:68 -j ACCEPT
# drop all other inbound traffic
-A INPUT -j DROP
# Forwarding rules
# forward packets along established/related connections
-A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
# forward from LAN (p1p1) to WAN (p4p1)
-A FORWARD -i enp7s5 -o enp9s0 -j ACCEPT
# allow traffic from our NAT pinhole
-A FORWARD -p tcp -d 192.168.99.100 --dport 80 -j ACCEPT
-A FORWARD -p tcp -d 192.168.99.102 --dport 7990 -j ACCEPT
-A FORWARD -p tcp -d 192.168.99.103 --dport 8085 -j ACCEPT
-A FORWARD -p tcp -d 192.168.99.104 --dport 8080 -j ACCEPT
-A FORWARD -p tcp -d 192.168.99.104 --dport 8090 -j ACCEPT
-A FORWARD -p tcp -d 192.168.99.105 --dport 8090 -j ACCEPT
-A FORWARD -p tcp -d 192.168.99.102 --dport 22 -j ACCEPT
-A FORWARD -p tcp -d 192.168.99.103 --dport 22 -j ACCEPT
-A FORWARD -p tcp -d 192.168.99.104 --dport 9014 -j ACCEPT
-A FORWARD -p tcp -d 192.168.99.105 --dport 22 -j ACCEPT
# drop all other forwarded traffic
-A FORWARD -j DROP
COMMIT
DHCP 服务器:
#
# Sample configuration file for ISC dhcpd for Debian
#
# Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as
# configuration file instead of this file.
#
#
# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;
# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
subnet 192.168.99.0 netmask 255.255.255.0 {
range 192.168.99.100 192.168.99.199;
option routers 192.168.99.1;
option domain-name-servers 192.168.99.1;
option broadcast-address 192.168.99.255;
host Bitbucket {
hardware ethernet 00:0f:fe:f6:34:ea;
fixed-address 192.168.99.103;
}
host LaptopMSI {
hardware ethernet 44:8a:5b:ef:e9:0f;
fixed-address 192.168.99.102;
}
host SkullCanyon {
hardware ethernet 00:1f:c6:9b:e2:20;
fixed-address 192.168.99.105;
}
host ConfluenceJira {
hardware ethernet fc:aa:14:65:31:e2;
fixed-address 192.168.99.104;
}
}
接口:# 此文件描述系统上可用的网络接口以及如何激活它们。有关更多信息,请参阅接口 (5)。
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto enp9s0
iface enp9s0 inet static
address 192.168.1.161
netmask 255.255.255.0
# This is an autoconfigured IPv6 interface
iface enp9s0 inet6 auto
auto enp7s5
iface enp7s5 inet static
address 192.168.99.1
netmask 255.255.255.0
感谢大家的帮助!
答案1
我认为问题在于你试图从一台位于第二NAT。
首先,您的服务器位于路由器后面的现有 NAT 池内,该池本身并不是可路由的地址(192.168.99.x)。
您的路由器/调制解调器应配置为桥接器,并且您的服务器外部 IP 应为 ISP 提供给您的 IP,然后您就可以让服务器对内部计算机进行 NAT。换句话说,您的 Linux 服务器将成为路由器,这没有什么不对。许多第三方路由器固件都是 Linux,事实上,我在大学学习 Linux 时就有一个类似的设置。我的路由器是 Linux 服务器 :D
由于您正在使用 Linux 作为“路由器”,我建议使用 Webmin 作为 CP,以便更轻松地进行配置。http://www.webmin.com/download.html