Linux Networking Basics for Configuring Network Interfaces and Firewalls

In Linux, networking is a fundamental aspect of system administration. Understanding how to configure network interfaces and firewalls is essential for managing network connectivity and security. In this tutorial, we'll cover the basics of Linux networking, including network interface configuration and firewall setup.

1. Network Interfaces

Network interfaces are physical or virtual connections to the network. Commonly used commands for managing network interfaces:

  • ifconfig: Display or configure network interfaces (deprecated, use ip command instead).
  • ip: Powerful command for network interface configuration and management.
  • ifup/ifdown: Bring up or take down network interfaces.

2. IP Address Configuration

To configure IP addresses for network interfaces:

ip addr add 192.168.1.10/24 dev eth0
ip addr delete 192.168.1.10/24 dev eth0

3. Network Routes

Routing determines how network traffic is directed. Useful commands for managing network routes:

ip route add 192.168.2.0/24 via 192.168.1.1
ip route delete 192.168.2.0/24

4. Firewalls

Firewalls control network traffic based on defined rules. Commonly used firewall utilities:

  • iptables: Traditional Linux firewall utility (deprecated in favor of nftables).
  • nftables: Modern replacement for iptables with enhanced features.
  • firewalld: Dynamic firewall management tool with support for zones and services.

5. Firewall Rules

To create firewall rules using nftables:

nft add rule inet filter input tcp dport 22 accept
nft add rule inet filter input tcp dport 80 accept

Conclusion

By understanding the basics of Linux networking, you'll be better equipped to configure network interfaces and firewalls to meet your system's requirements. Experiment with different commands and configurations to gain hands-on experience and enhance your networking skills.