Linux Firewalls and Networking Commands
Overview
Linux provides various tools for managing network configurations and firewalls. This document covers basic and commonly used commands for network management and firewall configuration.
Networking Commands
ifconfig
Displays or configures network interfaces.
Example
Example
ip
A more modern tool for managing network interfaces, routes, and addresses.
Show Network Interfaces
Example
Assign an IP Address
Example
sudo ip addr add 192.168.1.100/24 dev eth0
# Assigns the IP address 192.168.1.100 to the 'eth0' interface
Bring Up/Down an Interface
Example
netstat
Displays network connections, routing tables, interface statistics, and more.
Example
ss
A utility to investigate sockets and network connections, a modern replacement for netstat
.
Example
ping
Sends ICMP ECHO_REQUEST packets to network hosts.
Example
traceroute
Displays the route packets take to a network host.
Example
nslookup
Queries DNS to obtain domain name or IP address mapping.
Example
route
Displays or modifies the IP routing table.
Example
ip route
Displays and manages the routing table.
Example
Firewall Commands
iptables
Configures and manages firewall rules.
List Rules
Example
Add Rule
Example
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allows incoming TCP connections on port 22 (SSH)
Delete Rule
Example
sudo iptables -D INPUT -p tcp --dport 22 -j ACCEPT
# Deletes the rule allowing incoming TCP connections on port 22
ufw
Uncomplicated Firewall (UFW) is a user-friendly front-end for managing firewall rules.
Enable UFW
Example
Allow a Port
Example
Deny a Port
Example
Check UFW Status
Example
Summary
Linux provides a robust set of tools for managing network configurations and firewall rules. Mastering these commands helps in monitoring and securing network traffic, configuring network interfaces, and troubleshooting network issues. For more detailed information on each command, refer to the Linux manual pages.