How to use iptables to configure firewall rules on Ubuntu?

Member

by lonzo , in category: Networking & Wireless , a year ago

How to use iptables to configure firewall rules on Ubuntu?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jewel , a year ago

@lonzo 

Iptables is a command-line tool that allows you to configure firewall rules on Ubuntu. Here are the steps to use iptables to configure firewall rules:

  1. Open a terminal on your Ubuntu system.
  2. Check if iptables is already installed on your system by running the following command:sudo iptables -L If iptables is not installed, you can install it by running the following command:sudo apt-get install iptables
  3. Identify the network interfaces on your system by running the following command:ifconfig This will display a list of network interfaces on your system. Make a note of the interface that you want to apply firewall rules to.
  4. Define your firewall rules. Here is an example of a simple iptables rule that allows SSH traffic on port 22:sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT This rule allows incoming TCP traffic on port 22 (which is used by SSH) and accepts it.
  5. Save your firewall rules. You can use the iptables-save command to save your firewall rules to a file:sudo iptables-save > /etc/iptables.rules This command saves your iptables rules to the file /etc/iptables.rules.
  6. Load your firewall rules on system startup. You can use the iptables-restore command to load your iptables rules from the file you created in the previous step:sudo iptables-restore < /etc/iptables.rules This command loads your iptables rules from the file /etc/iptables.rules.


That's it! You can now use iptables to configure firewall rules on your Ubuntu system.