> For the complete documentation index, see [llms.txt](https://riteshs4hu.gitbook.io/infosec-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://riteshs4hu.gitbook.io/infosec-notes/linux-server-administrator/network-configuration.md).

# Network Configuration

Network configuration in Linux is an essential task for administrators to manage IP addresses, DNS settings, routing tables, and network interfaces efficiently.

***

### Configuration Commands

* Show the current system hostname:

  ```sh
  hostname
  ```
* Display detailed hostname information:

  ```sh
  hostnamectl
  ```
* List all network interfaces and their statuses:

  ```sh
  nmcli device status
  ```
* Show detailed IP address configuration:

  ```sh
  ip addr show
  ```
* View the default gateway and routing table:

  ```sh
  ip route
  ```
* Show the configured DNS servers:

  ```sh
  cat /etc/resolv.conf
  ```
* Display ARP cache:

  ```sh
  ip neigh show
  ```

***

### Configuring Network Interfaces

#### Manual Configuration via NetworkManager

1. Navigate to the network connections directory:

   ```sh
   cd /etc/NetworkManager/system-connections/
   ```
2. Open the configuration file for the interface (e.g., `enp0s3`):

   ```sh
   vim enp0s3.nmconnection
   ```
3. Configure a static IP address:

   ```ini
   [connection]
   id=static-connection
   type=ethernet
   interface-name=enp0s3

   [ipv4]
   method=manual
   addresses=192.168.1.100/24
   gateway=192.168.1.1
   dns=8.8.8.8;8.8.4.4;

   [ipv6]
   method=ignore
   ```
4. Apply changes:

   ```sh
   sudo nmcli connection reload
   sudo nmcli connection up enp0s3
   ```

#### Using `nmtui` (NetworkManager Text User Interface)

`nmtui` is a graphical interface for managing network settings.

**Installation**

* **CentOS**:

  ```sh
  dnf install NetworkManager-tui
  ```
* **Debian/Ubuntu**:

  ```sh
  apt install network-manager
  ```
* Launch `nmtui`:

  ```sh
  sudo nmtui
  ```

***

### Network Troubleshooting and Monitoring

#### `ifconfig` (Deprecated, Use `ip` Instead)

* Display all network interfaces:

  ```sh
  ifconfig -a
  ```
* Temporarily assign an IP address:

  ```sh
  sudo ifconfig enp0s3 192.168.1.150 netmask 255.255.255.0 up
  ```

#### `ping` (Check Network Connectivity)

* Verify connectivity to a domain:

  ```sh
  ping example.com
  ```
* Send packets of a specific size:

  ```sh
  ping -s 1000 8.8.8.8
  ```
* Limit the number of pings:

  ```sh
  ping -c 5 8.8.8.8
  ```

#### `traceroute` (Trace Packet Path)

* Trace the route to a host:

  ```sh
  traceroute google.com
  ```
* Use UDP instead of ICMP:

  ```sh
  traceroute -U google.com
  ```

#### `tcptraceroute` (Trace TCP Packets)

* Trace the route using TCP:

  ```sh
  tcptraceroute google.com 80
  ```

#### `ss` (Socket Statistics)

* Display all listening ports:

  ```sh
  ss -tuln
  ```
* Show established connections:

  ```sh
  ss -ntp
  ```
* Filter TCP connections:

  ```sh
  ss -at
  ```

#### `netstat` (Legacy Network Monitoring Tool)

* Show active connections:

  ```sh
  netstat -ant
  ```
* Display listening services:

  ```sh
  netstat -ltn
  ```
* View statistics for each protocol:

  ```sh
  netstat -s
  ```

#### `lsof` (List Open Files and Ports)

* Show all network connections:

  ```sh
  sudo lsof -i
  ```
* List processes using a specific port:

  ```sh
  sudo lsof -i :443
  ```

#### `arp` (View MAC Address Table)

* Show the ARP table:

  ```sh
  arp -a
  ```
* Clear the ARP cache:

  ```sh
  sudo ip -s -s neigh flush all
  ```

#### `ethtool` (View/Modify Ethernet Device Settings)

* Show interface capabilities:

  ```sh
  ethtool enp0s3
  ```
* Enable auto-negotiation:

  ```sh
  sudo ethtool -s enp0s3 autoneg on
  ```
