How to set IP configuration from Linux minimal install command line
How to Configure a Linux IP Address from the Command Line
This guide explains how to view a network interface, reset its IP configuration,
enable DHCP using nmcli, and configure a legacy interface file on
RHEL-based Linux systems.
1. View Current Network Interfaces
Use the following command to display the current network interfaces and assigned IP addresses:
ip addr
2. Reset an Interface Before Reconfiguration
If you need to clear the current IP settings on an interface such as
ens33, bring the interface down and flush its assigned addresses.
sudo ip link set ens33 down
sudo ip addr flush dev ens33
This is useful when removing an existing static or DHCP-assigned address before applying new settings.
3. Bring Up a NetworkManager Connection
To activate a NetworkManager connection, use:
nmcli connection up <interface_name>
Example:
nmcli connection up ens33
4. Configure an Interface for DHCP Using nmcli
To switch an interface to DHCP and remove any previously defined static IPv4 settings, run:
nmcli con mod ens33 ipv4.method auto ipv4.addresses "" ipv4.gateway ""
ip link set ens33 down
nmcli connection up ens33
systemctl restart network
This sequence performs the following actions:
- Sets the IPv4 method to automatic (DHCP)
- Clears any manually configured IPv4 address
- Clears any manually configured gateway
- Brings the interface down
- Reactivates the NetworkManager connection
- Restarts the network service
5. Configure a Legacy Interface File
On some RHEL-based systems, network settings may still be managed using legacy interface configuration files. Edit the interface file with:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
Example configuration for DHCP:
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
After saving the file, restart networking:
systemctl restart network
6. Notes and Best Practices
- Use
ip addrbefore and after changes to verify the result. - Confirm the correct interface name before applying commands, as modern Linux systems often use names like
ens33instead ofeth0. - On systems managed by NetworkManager, prefer
nmcliover manual file edits where possible. - Be cautious when running these commands remotely, as bringing an interface down may disconnect your session.
7. Example: Install Git After Network Configuration
Once networking is working correctly, you can install packages such as Git:
dnf install -y git