我有一台主机, 我试着使用iptables限制来自公网对其的访问,只开放22和655端口在公网里,同时允许121.201.24.85 这一ip不受这一限制。此外,这个机器做了nat网关,负责转发内网机器的请求。
问题是 在我这样配置之后,我无法在这台主机内部访问到公网,dns解析没问题,ping外网ip也通,感觉是到外网的tcp出了问题
iptables -A POSTROUTING -t nat -o eno1 -j MASQUERADE
iptables -I INPUT -d 58.51.101.7 -p tcp -j DROP
iptables -I INPUT -d 58.51.101.7 -p tcp --dport 22 -j ACCEPT
iptables -I INPUT -d 58.51.101.7 -p tcp --dport 655 -j ACCEPT
iptables -I INPUT -d 58.51.101.7 -p udp --dport 655 -j ACCEPT
iptables -I INPUT -s 121.201.24.85 -p tcp -j ACCEPT
iptables -I INPUT -s 58.51.101.7 -j ACCEPT
iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 58.51.101.7 anywhere
ACCEPT tcp -- 121.201.24.85 anywhere
ACCEPT udp -- anywhere 58.51.101.7 udp dpt:tinc
ACCEPT tcp -- anywhere 58.51.101.7 tcp dpt:tinc
ACCEPT tcp -- anywhere 58.51.101.7 tcp dpt:ssh
DROP tcp -- anywhere 58.51.101.7
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
求帮助
试试这样? 允许从本机访问外网.
要不, 直接允许所有出站请求?