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 -j ACCEPT
iptables -I OUTPUT -p tcp -d -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
-A INPUT -s -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 ! -i lo -j REJECT --reject-with icmp-port-unreachable
-A INPUT -i tun0 -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 -p tcp -j ACCEPT
# 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?

1 Answer 1


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, 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 -j ACCEPT

And remove the OUTPUT rule you made for

  • Tell me please how to allow outgoing ssh connection?
    – iWizard
    Jun 22, 2017 at 7:52
  • They are allowed, if the rule set is the one you've pasted in your question. Allowed by the combination of two rules: "-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT" + the output/Accept one.
    – Marco
    Jun 22, 2017 at 7:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .