大网数据广告活动
服务器运维问答

How to setup IPTables to allow TCP port 599?

· 52CE 我爱测

I'm new to IPTables and I believe I'm overlooking something obvious. This is my settings: Chain INPUT (policy ACCEPT) target prot opt source destination DROP all -- anywhere anywhere state NEW recent: UPDATE seconds: 60 hit_count…

问题原文

原帖链接 · Houman · CC BY-SA 3.0

I'm new to IPTables and I believe I'm overlooking something obvious.

This is my settings:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
DROP       all  --  anywhere             anywhere             state NEW recent: UPDATE seconds: 60 hit_count: 12 name: DEFAULT side: source mask: 255.255.255.255
           all  --  anywhere             anywhere             state NEW recent: SET name: DEFAULT side: source mask: 255.255.255.255
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:ssh
ACCEPT     all  --  anywhere             anywhere
DROP       all  --  anywhere             anywhere             state INVALID
ACCEPT     udp  --  anywhere             anywhere             udp dpt:isakmp
ACCEPT     udp  --  anywhere             anywhere             udp dpt:ipsec-nat-t
DROP       all  --  anywhere             anywhere

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  ip-10-10-10-0.ap-south-1.compute.internal/24  anywhere             policy match dir in pol ipsec proto esp
ACCEPT     all  --  anywhere             ip-10-10-10-0.ap-south-1.compute.internal/24  policy match dir out pol ipsec proto esp
DROP       all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Then I tried to open port 599:

sudo iptables -A INPUT -p tcp --dport 599 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 599 -m conntrack --ctstate ESTABLISHED -j ACCEPT

Unfortunately, my existing IPTables still blocks it and I don't understand why. AWS health check still can't do a TCP ping on 599 port. Any clue what I'm missing?

Latest UPDATE:

sudo iptables -vnL --line-numbers



 Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination
1    11582  695K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:599 ctstate NEW,ESTABLISHED
2     309K   19M DROP       all  --  eth0   *       0.0.0.0/0            0.0.0.0/0            state NEW recent: UPDATE seconds: 60 hit_count: 12 name: DEFAULT side: source mask: 255.255.255.255
3     6546  386K            all  --  eth0   *       0.0.0.0/0            0.0.0.0/0            state NEW recent: SET name: DEFAULT side: source mask: 255.255.255.255
4    11329 7186K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
5       24  1440 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:599 ctstate NEW,ESTABLISHED
6      246 13224 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22
7        0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
8       50  2227 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            state INVALID
9        2   400 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:500
10       0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:4500
11    6275  371K DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination
1        0     0 ACCEPT     all  --  *      *       10.10.10.0/24        0.0.0.0/0            policy match dir in pol ipsec proto 50
2        0     0 ACCEPT     all  --  *      *       0.0.0.0/0            10.10.10.0/24        policy match dir out pol ipsec proto 50
3        0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain OUTPUT (policy ACCEPT 18608 packets, 2153K bytes)
num   pkts bytes target     prot opt in     out     source               destination

已采纳解答

原帖链接 · lsd · CC BY-SA 3.0

Well, iptables -A INPUT appends a rule to the end. Your current last rule is:

DROP all -- anywhere anywhere

So, it gets added to the end, after the drop rule, and never gets reached. You will want to list rules with line numbers:

iptables -nL --line-numbers

Then use iptables -I INPUT 5 ... (or whatever line number) to add at a specific position.

If all traffic for port 599 should be allowed back out (with NEW,ESTABLISHED), so you shouldn't need the OUTPUT rule.

If this is running on an ec2 instance, you'll want to make sure security groups allow 599 in also. Although with aws security groups, iptables on the individual instances may not quite be necessary...

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-11-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。