Networking in RHEL/LINUX

In Red Hat Enterprise Linux (RHEL), managing networking involves several commands for configuring network interfaces, checking connectivity, and troubleshooting network-related issues. Here are some essential networking commands frequently used in RHEL:

1. Network Configuration

1.1. NetworkManager Commands

NetworkManager is the default service for managing network interfaces in RHEL. Here are some commands to manage NetworkManager:

  • View NetworkManager Status:

      systemctl status NetworkManager
    
  • Start/Stop/Restart NetworkManager:

      systemctl start NetworkManager
      systemctl stop NetworkManager
      systemctl restart NetworkManager
    
  • Enable/Disable NetworkManager (for startup):

      systemctl enable NetworkManager
      systemctl disable NetworkManager
    
  • List Network Interfaces Managed by NetworkManager:

      nmcli device status
    
  • Configure Network Interface with nmcli:

      nmcli connection add type ethernet ifname eth0 con-name "Wired Connection 1" autoconnect yes
    

    Replace eth0 with your interface name and adjust connection parameters as needed.

1.2. Legacy Network Configuration (ifcfg files)

For systems using traditional network configuration files (ifcfg files under /etc/sysconfig/network-scripts/), commands typically include:

  • List Network Interfaces:

      ip addr show
    
  • Edit Network Interface Configuration:

      sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
    

    Adjust eth0 based on your interface name.

  • Restart Network Service:

      sudo systemctl restart network
    

2. Network Connectivity

2.1. Checking IP Address and Routes

  • View IP Address of Interfaces:

      ip addr show
    
  • Display Routing Table:

      ip route show
    

2.2. Testing Connectivity

  • Ping a Remote Host:

      ping -c 4 google.com
    

    Replace google.com with the host you want to ping.

  • Check Open Ports (for troubleshooting):

      sudo netstat -tuln
    

3. DNS Configuration

3.1. Checking DNS Settings

  • Check Current DNS Servers (via systemd-resolved):

      systemd-resolve --status
    
  • Edit DNS Configuration: Edit /etc/resolv.conf or use NetworkManager's nmcli for dynamic management.

4. Firewall and Security

  • Firewalld Commands:

      systemctl status firewalld
      sudo firewall-cmd --list-all
      sudo firewall-cmd --zone=public --add-service=http --permanent
      sudo firewall-cmd --reload
    

5. Network Diagnostics and Troubleshooting

  • Network Troubleshooting with ip and nmcli:

      ip link
      ip addr
      ip route
      nmcli connection show
      nmcli device show
    
  • Packet Capture (using tcpdump):

      sudo tcpdump -i eth0
    

    Replace eth0 with your interface.