Thursday, June 06, 2024

RHEL9 - Set static IP address

Requirement: Assign static IP address on enp0s3 interface:

·       IP: 192.168.56.56
·       netmask: 255.255.255.0
·       gateway: 192.168.56.1
·       dns: 8.8.8.8


1. Check information

[root@barman ~]# systemctl status NetworkManager.service

[root@barman ~]# NetworkManager --print-config

[root@barman ~]# nmcli device

 DEVICE  TYPE      STATE                   CONNECTION
 enp0s8  ethernet  connected               enp0s8   
 enp0s3  ethernet  connected               enp0s3   
 lo      loopback  connected (externally)  lo    
 

 [root@barman ~]# nmcli connection show

 NAME    UUID                                  TYPE      DEVICE
 enp0s8  a2be3b45-4395-35ab-ba08-e6c7ba92d236  ethernet  enp0s8
 enp0s3  247f61a8-b997-3f30-88ea-688882942b52  ethernet  enp0s3
 lo      b259c109-60d7-4682-8016-192ebb4de8ae  loopback  lo    

  

[root@barman ~]# ls -l /etc/NetworkManager/system-connections/

 total 8
 -rw-------. 1 root root 229 Jun  6 10:37 enp0s3.nmconnection
 -rw-------. 1 root root 229 Jun  6 10:37 enp0s8.nmconnection

 

[root@barman ~]# ip addr show enp0s3

[root@barman ~]# cat /etc/NetworkManager/system-connections/enp0s3.nmconnection

  

2. Network Configuration

[root@barman ~]# nmcli connection modify 'enp0s3' ifname enp0s3 ipv4.method manual ipv4.addresses 192.168.56.56/24 gw4 192.168.56.1 ipv4.dns 8.8.8.8

[root@barman ~]# nmcli connection down 'enp0s3'

[root@barman ~]# nmcli connection up 'enp0s3'

 

3. Verify configuration

 [root@barman ~]# ip addr show enp0s3

 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
     link/ether 08:00:27:46:ea:cf brd ff:ff:ff:ff:ff:ff
     inet 192.168.56.56/24 brd 192.168.56.255 scope global noprefixroute enp0s3
        valid_lft forever preferred_lft forever
     inet6 fe80::a00:27ff:fe46:eacf/64 scope link noprefixroute
        valid_lft forever preferred_lft forever

 

[root@barman ~]# ip route show

default via 192.168.22.1 dev enp0s8 proto dhcp src 192.168.22.152 metric 101
default via 192.168.56.1 dev enp0s3 proto static metric 102
192.168.22.0/24 dev enp0s8 proto kernel scope link src 192.168.22.152 metric 101
192.168.56.0/24 dev enp0s3 proto kernel scope link src 192.168.56.56 metric 102

 

[root@barman ~]# cat /etc/NetworkManager/system-connections/enp0s3.nmconnection

[connection]
id=enp0s3
uuid=247f61a8-b997-3f30-88ea-688882942b52
type=ethernet
autoconnect-priority=-999
interface-name=enp0s3
timestamp=1717645810

[ethernet]

[ipv4]
address1=192.168.56.56/24,192.168.56.1
dns=8.8.8.8;
method=manual

[ipv6]
addr-gen-mode=eui64
method=auto

[proxy]