# System Networking

Networking configuration and commands

# Networking Commands

<span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">====================================================================================</span></span>

#### Show networking information

show current networking configuration and status

```
ip a
```

Show IPv4 or IPv6 specifically

```
ip -4 a

ip -6 a
```

Show IPs assigned to interfaces in simple format

```
ip -br addr
```

show network interfaces

```
ip l
```

show configuration for a specific interface

```
ip a s interfacename
```

show route table

```
ip r
```

show arp cache

```
ip n
```

<span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">------------------------------------------------------------------------------------------------------------------------------------------ </span></span><span class="EOP SCXO41186676 BCX0"> </span>

#### Changing networking information

Add an IP address to an interface:

```
ip a a IPADDRESS dev interfacename
```

Delete an IP from an interface

<span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">====================================================================================</span></span>

#### <span class="EOP SCXO41186676 BCX0">Network Troubleshooting</span>

<span class="EOP SCXO41186676 BCX0"><span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">------------------------------------------------------------------------------------------------------------------------------------------ </span></span> </span>

##### <span class="EOP SCXO41186676 BCX0">traceroute/6</span>

<span class="EOP SCXO41186676 BCX0">The traceroute command is used to send a request to a domain/IP. The output then includes each server that the request has passed through to get to the target:</span>

```
root@test:~# traceroute google.com
traceroute to google.com (142.250.185.78), 30 hops max, 60 byte packets
 1  pfsense.b4sed.xyz (192.168.1.1)  0.162 ms  0.120 ms  0.097 ms
 2  100.88.196.1 (100.88.196.1)  0.374 ms  0.392 ms  0.372 ms
 3  core23.fsn1.hetzner.com (213.239.203.141)  0.432 ms core22.fsn1.hetzner.com (213.239.254.113)  5.252 ms core23.fsn1.hetzner.com (213.239.203.141)  0.383 ms
 4  core21.fsn1.hetzner.com (213.239.224.14)  5.029 ms core5.fra.hetzner.com (213.239.224.78)  5.003 ms  4.982 ms
 5  72.14.218.176 (72.14.218.176)  5.067 ms 142.250.160.234 (142.250.160.234)  5.087 ms 72.14.218.94 (72.14.218.94)  6.109 ms
 6  * * *
 7  142.250.214.190 (142.250.214.190)  5.225 ms fra16s48-in-f14.1e100.net (142.250.185.78)  5.223 ms 142.250.210.208 (142.250.210.208)  6.215 ms
```

You can also use traceroute for IPv6 connections:

```
traceroute6 ip/hostname
```

<span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">------------------------------------------------------------------------------------------------------------------------------------------ </span></span><span class="EOP SCXO41186676 BCX0"> </span>

##### <span class="EOP SCXO41186676 BCX0">mtr ( My TraceRoute)</span>

<span class="EOP SCXO41186676 BCX0">The mtr command is very similar to traceroute, except the data is formatted more nicely, and the output continuously updates.</span>

```
mtr google.com

 Host                                           Loss%   Snt   Last   Avg  Best  Wrst StDev
 1. pfsense.b4sed.xyz                           0.0%    33    0.3   0.2   0.2   0.4   0.1
 2. 100.88.196.1                                0.0%    33    9.8   1.1   0.4   9.8   1.7
 3. core21.fsn1.hetzner.com                     0.0%    33    3.2   1.2   0.5   6.1   1.4
 4. hos-tr4.ex3k5.dc4.fsn1.hetzner.com          0.0%    32    5.3   5.3   5.1   5.6   0.1
 5. 142.250.160.234                             0.0%    32    5.2   5.4   5.1   6.5   0.3
 6. 72.14.239.217                               0.0%    32    5.4   5.6   5.2   7.1   0.4
 7. 142.250.62.151                              0.0%    32    5.4   5.3   5.2   5.5   0.1
 8. fra16s48-in-f14.1e100.net                   0.0%    32    5.3   5.3   5.1   5.5   0.1
```

<span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">------------------------------------------------------------------------------------------------------------------------------------------ </span></span><span class="EOP SCXO41186676 BCX0"> </span>

##### <span class="EOP SCXO41186676 BCX0">tracepath/6</span>

<span class="EOP SCXO41186676 BCX0">Tracepath is similar to both of the above commands, however, it has more of a focus on the connection to each host. Tracepath spends 30 seconds analysis the connection between the local machine, and each machine identified as a hop in the trace, making it ideal to identify whether slow responses from a device on the trace are causing slow loading issues.</span>

<span class="EOP SCXO41186676 BCX0">You can also use tracepath for IPv6 connections:</span>

```
traceroute6 ip/hostname
```

<span class="EOP SCXO41186676 BCX0"><span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">====================================================================================</span></span></span>

# Network Managers

<span class="TextRun SCXO38321458 BCX0" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO38321458 BCX0">====================================================================================</span></span>

### Ubuntu - Netplan

Before making changes to the network configuration on an Ubuntu machine, ensure that Cloud-init isn't enabled. Cloud-init is essentially Canonicals attempt at having Ubuntu servers fully configure themselves, in terms of networking, Cloud-init will force an Ubuntu machine to attempt to automatically configure it's networking

Netplan uses .yaml files for network configuration, these are stored in /etc/netplan

Check DHCP IP leases info

```
netplan ip leases interfacename
```

Changes to interfaces are made in the .yaml files, once changes have been made they need to be applied.

To test changes, use the try command. This essentially implements the change for a set amount of time, after which the change is reverted.

```
netplan try
```

You can also set a custom timeout time using the below command:

```
netplan try --timeout=15
```

To permanently apply a change, use the below command:

```
netplan apply
```

<span class="TextRun SCXO38321458 BCX0" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO38321458 BCX0">====================================================================================</span></span>

### <span class="TextRun SCXO38321458 BCX0" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO38321458 BCX0">RHEL - nmcli</span></span>

<span class="TextRun SCXO38321458 BCX0" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO38321458 BCX0">Network configuration files are stored in /etc/syconfig/network-scripts. Files stored within this directory shouldn't really be edited - these are used for functionality of the ifconfig command, rather than being the interface configuration itself.</span></span>

#### <span class="TextRun SCXO38321458 BCX0" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO38321458 BCX0">Viewing network configuration</span></span>

<span class="TextRun SCXO38321458 BCX0" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO38321458 BCX0">View interface connections</span></span>

```
nmcli connection show
```

View interface device status

```
nmcli device status
```

View network device configuration

```
nmcli device show devicename
```

#### Editing network settings &amp; configuration

##### Edit connection settings

```
nmcli connection edit connectionname
```

From here, you can edit any of the settings shown in the 'nmcli device show devicename' command

As an example, the below could be used to change the default gateway IP

```
set ipv4.gateway 10.0.0.2
```

You would then want to save changes, you're given the option to trial the change or save it permanently

```
save persistent
```

or

```
save temporary
```

The above uses the nmcli cli to make changes, you can also format commands as below to make changes without entering the dedicated cli:

Add an additional IP to a connection

```
nmcli connection modify connectionname ipv4.addresses oldIP, newIP
```

##### <span class="TextRun SCXO38321458 BCX0" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO38321458 BCX0">Delete a connection</span></span>

```
nmcli connection delete connectionname
```

Once changes have been made via nmcli, the interface will need restarting

```
nmcli connection down

nmcli connection up
```

or

```
nmcli connection reload
```

<span class="TextRun SCXO38321458 BCX0" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO38321458 BCX0">====================================================================================</span></span>

### OpenSUSE - Wicked

Network configuration files are stored in /etc/sysconfig/networks

systemctl status network

Show all interfaces

```
wicked show all
```

Show info for specific interface

```
wicked show eth1
```

Take interface down or up

```
wicked ifdown eth1

wicked ifup eth1
```

# DNS and Hosts Resolution

<span class="TextRun SCXO38321458 BCX0" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO38321458 BCX0">====================================================================================</span></span>

### <span class="TextRun SCXO38321458 BCX0" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO38321458 BCX0">DNS and Hosts Testing</span></span>

<span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">------------------------------------------------------------------------------------------------------------------------------------------------</span></span>

```
dig domainname
```

dig from a specific DNS server

```
dig domainname @DNS_ServerIP
```

<span class="TextRun SCXO38321458 BCX0" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO38321458 BCX0">====================================================================================</span></span>

### DNS and Host Resolution

<span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">------------------------------------------------------------------------------------------------------------------------------------------------</span></span>

#### <span class="EOP SCXO41186676 BCX0">/etc/resolv.conf</span>

<span class="EOP SCXO41186676 BCX0">The /etc/resolv.conf file is used to configure DNS server that your server will use for DNS lookups. </span>

*<span class="EOP SCXO41186676 BCX0">Important Note; The below documentation is related to the /etc/resolve.conf file. This is not the primary file that Linux machines will use for the resolution configuration. Instead, this file is symlinked to /run/systemd/resolve/stub-resolve.conf which is referenced by systemd-resolvd. The primary configuration file used by systemd-resolvd is /run/systemd/resolve/resolve.conf, but stub-resolv.conf is also referenced. TLDR; /etc/resolve.conf is still used, but it's not the primary place referenced by systemd-resolvd.</span>*

```
root@test:~# ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Aug 10  2023 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
```

<span class="EOP SCXO41186676 BCX0">The systemd-resolved service listens on port 53 locally: this port needs to be open in order for DNS resolution to function.</span>

```
root@test:~# lsof -i:53
COMMAND      PID            USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
systemd-r 127318 systemd-resolve   13u  IPv4 1028696      0t0  UDP localhost:domain
systemd-r 127318 systemd-resolve   14u  IPv4 1028697      0t0  TCP localhost:domain (LISTEN)
```

##### <span class="EOP SCXO41186676 BCX0">/etc/Resolve.conf config:</span>

Below is a typical default configuration you might see on a Linux system:

```
# This file configures your system's DNS resolution.

nameserver 127.0.0.53  # Local DNS server (systemd-resolved)
options edns0 trust-ad  # Enables EDNS for performance 
search b4sed.xyz        # Search domain to append to incomplete names
```

<span class="EOP SCXO41186676 BCX0">`nameserver` - specifies where the system looks for DNS resolution</span>

`<span class="EOP SCXO41186676 BCX0">search</span>` - This is the default search domain. For example, if a lookup is made to google, this option would append .b4sed.xyz to the end: google.b4sed.xyz

`<span class="EOP SCXO41186676 BCX0">options:</span>`

<span class="EOP SCXO41186676 BCX0"> `edns0` - enables a potentially performance-enhancing feature.</span>

<span class="EOP SCXO41186676 BCX0"> `trust-ad` - instructs your resolver to accept and potentially use the information in the Additional Records section without further verification.</span>

##### <span class="EOP SCXO41186676 BCX0">View current DNS configuration:</span>

```
resolvectl status
```

<span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">------------------------------------------------------------------------------------------------------------------------------------------------</span></span>

#### /etc/hosts

The /etc/hosts file can be thought of as essentially a local DNS configuration. This means that DNS entries can be mapped here, overwriting any DNS entries provided by an external service.

Entries into the /etc/hosts file can be formatted as follows:

```
IP domainname
```

<span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">------------------------------------------------------------------------------------------------------------------------------------------------</span></span>

# ARP

show arp cache

arp -a