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

How to allow all connections from specific IP address?

· 52CE 我爱测

I want to allow all connections from a specific IP address but I'm failing. OS: Ubuntu Server 16.04. (incoming and outgoing server) I have executed these commands: iptables -I INPUT -p tcp -s 192.168.0.45 -j ACCEPT iptables -I OU…

问题原文

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

I want to allow all connections from a specific IP address but I'm failing.

OS: Ubuntu Server 16.04. (incoming and outgoing server)

I have executed these commands:

iptables -I INPUT -p tcp -s 192.168.0.45 -j ACCEPT
iptables -I OUTPUT -p tcp -d  192.168.0.45 -j ACCEPT

service netfilter-persistent save
/etc/init.d/netfilter-persistent restart

But it is not working.

This is what my rules.v4 looks like:

# Generated by iptables-save v1.6.0 on Thu Jun 22 08:48:43 2017
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -s 192.168.0.45/32 -p tcp -j ACCEPT
-A INPUT -p tcp -m tcp --dport 9100 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8025 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 ! -i lo -j REJECT --reject-with icmp-port-unreachable
-A INPUT -i tun0 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 17000 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
-A INPUT -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -j REJECT --reject-with icmp-port-unreachable
-A OUTPUT -d 192.168.0.45/32 -p tcp -j ACCEPT
-A OUTPUT -j ACCEPT
COMMIT
# Completed on Thu Jun 22 08:48:43 2017

I'm receiving all connections only if I flush all with

iptables -F

How to properly allow all connections from specific IP address?

已采纳解答

原帖链接 · Marco · CC BY-SA 4.0

How to properly allow all connections from specific IP address?

"All connections" means don't match tcp on your specific IP allow rule!

Just remove -p tcp and you'll have ping (ICMP) and all the other IP protocol stuff allowed.

Also please note that the OUTPUT rule here is not useful. With the first rule you allow tcp to 192.168.0.45, with the second one you allow anything to anybody. So the first one has no effect!

In order to get what you want edit the input rule:

iptables -A INPUT -s 192.168.0.45/32 -j ACCEPT

And remove the OUTPUT rule you made for 192.168.0.45.

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

资料来源与适用范围

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

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

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