> For the complete documentation index, see [llms.txt](https://alicenab.gitbook.io/linux/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alicenab.gitbook.io/linux/redhat/tasks/test-and-inspect-current-network-configuration-with-command-line-utilities/ip-connection.md).

# ip-connection

## Task 1:

Set this configurations on your redhat host:

Gateway - 192.168.2.2

IPv4 - 192.168.2.3

Netmask - 255.255.255.0

DNS - 8.8.8.8

***

### nmcli

Deleting previous records:

```
nmcli connection delete <NAME>
nmcli connection delete ens160
```

Adding new record:

```
nmcli device show
#then:

nmcli connection add con-name VNAT type thernet ifname ens160

# or
nmcli connection add con-name VNAT type ethernet \
    ipv4.method manual ipv4.addresses 19.168.2.4/24 \
    ipv4.gateway 192.168.2.2 ipv4.dns 8.8.8.8
    
# enable autoconnect
nmcli con mod VNAT connection.autoconnect yes
```

If required, you can down and up the connection:

```
nmcli con down <connection_name>
nmcli con up <connection_name>
```

### nmcli the old way:

In old releases, ifconfig creates scripts and adds to network-scripts folder, this is deprecated but it is worth to know for debugging purposes:

```
sudo vim /etc/sysconfig/network-scripts/ifcfg-vnat2
```

```
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=vnat2
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.2.10
PREFIX=24
GATEWAY=192.168.2.10
```

You can add then start the connection by:&#x20;

```
sudo nmcli con reload # or command below
sudo systemctl restart NetworkManager

nmcli con down vnat2
nmcli con up vnat2
```

### ip

Set down interface ens160 (if necessary):

```
ip link set down dev ens160
```

Delete ipv4 address and routing from device ens160:

```
ip addr del 192.168.2.4/24 dev ens160
ip route del default via 192.168.2.2 
```

Set device up, because either is will not work:

```
ip link set up dev ens160 
```

Set new ipv4 address and route:

```
ip addr add 192.168.2.5/24 dev ens160
ip route add default via 192.168.2.2 dev ens160
```

## Task 2:

Create new network connection with existing interface (enp1s0) using provided values:

IPv4: 172.25.X.10/255.255.255.0 (where X is your domain number: Domain 15)&#x20;

Gateway: 172.25.X.2&#x20;

DNS server: 172.25.X.2&#x20;

Add the following secondary IP addresses statically to your current running connection. Do this is a way that does not compromise your existing settings:&#x20;

IPv4: 10.0.0.5/24 and set the hostname node1.domain15.example.com

### nmcli solution

Create a New Network Connection:

```
nmcli con add con-name primary-connection ifname enp1s0 type ethernet ip4 172.25.15.10/24 gw4 172.25.15.2
nmcli con mod primary-connection ipv4.dns 172.25.15.2
nmcli con up primary-connection
```

Add secondary IPv4 address:

```
nmcli con mod primary-connection +ipv4.addresses 10.0.0.5/24
nmcli con up primary-connection
ip addr show enp1s0
```

Set hostname:

```
sudo hostnamectl set-hostname node1.domain15.example.com
# making hostname settings permanent:
echo "node1.domain15.example.com" | sudo tee /etc/hostname
# verify changes:
hostnamectl
```
