Open/Close Ports on Ubuntu distributions

IPTables is an application program that allows to set up, maintain, and inspect the tables of IP packet filter rules provided by the Linux kernel.

All IPTables rules are stored on /etc/iptables.rules
You can open/close any port from it and then restart the network by running “etc/init.d/networking restart”

Before opening or closing ports, we recommend to first verify if the port is open or closed and who is using the port. There a number of different commands:

Commands to verify ports:

nmap IP#
nmap localhost
netstat –ntulp

to verify single port

netstat -nap | grep  <port #>

to list all current rules in iptables

iptables -L

For opening a TCP port:

iptables -A INPUT  -p tcp –dport <port #> -j ACCEPT

For opening a UDP port:

iptables -A INPUT -p udp –sport <port #>  -j ACCEPT

Save changes:

iptables-save > /etc/iptables.rules

If you need to disable the firewall temporarily, you can flush all the rules using:

iptables -F

————————————————————————————————————

For more detailed information visit

Iptables Description by Ubuntu Manuals

Iptables How-To for Ubuntu by Ubuntu Manuals

Iptables How-To for Debian by wiki.debian.org

  • 147 Users Found This Useful
Was this answer helpful?

Related Articles

Direct emailing

Direct email delivery is disabled on the network for server packaged ordered after 5/15/2012....

Check and open ports in CentOS / Fedora / Redhat

  If you want to open or close a port for a Linux firewall you have to edit the rules in the...

Get started with your Control Panel (Webmin/cPanel)

  Webmin: Webmin is disabled by default, you will have to enable it: - Access the server via...

Run File System Check in Linux

  # fsck fsck is used to check and optionally repair one or more Linux file systems....

How to restart Webmin

Here is a little helper if your Webmin does not respond. Just run this command from the...