Open port from specific source ip using ufw, iptables and firewalld
This is very common requirement for every linux admin while dealing with a service secuirty, Where we need to open certain port from specific source ip only.
Below is example using ufw ubuntu firewall, redhat firewalld and with generic iptables rule.
In below example i am trying to open port 9090 for only 192.168.1.2. If i wish to open it for entire subnet, i can simply provide 192.168.1.0/24 instead 192.168.1.2.
- firewalld
# firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.2" port protocol="tcp" port="9090" accept'
- ufw
$ sudo ufw allow from 192.168.1.2 to any port 9090
- iptables
$ iptables -I INPUT -p tcp -s 192.168.1.2 --dport 9090 -j ACCEPT
Comments
Post a Comment