Table of Contents

Redhat - Networking - Set IP

Set Temporarily IP

1. Set IP and netmask.

ifconfig eth0 10.20.1.10 netmask 255.255.255.0 up

where:

2. Set default gateway.

route add default gw 10.20.1.1

where:

3. Check the configuration.

Check the gateway:

route -n

Check the ip address:

ifconfig 

Set Permanent IP

1. Go to folder /etc/sysconfig/network-scripts

cd /etc/sysconfig/network-scripts

2. Backup your existing configuration.

cp ifcfg-eth0 ifcfg-eth0.bak

3. Edit ifcfg-eth0 with your favorite editor

vi ifcfg-eth0

4. Add below line to the ifcfg-eth0 file to setup your ip

ifcfg-eth0
BOOTPROTO=static
DEVICE=eth0
IPADDR=10.20.1.20
NETMASK=255.255.255.0
NETWORK=10.20.1.0
ONBOOT=yes
TYPE=Ethernet

5. Save the file.

6. Add below line to /etc/sysconfig/network to set your gateway.

GATEWAY=10.20.1.1

7. Save and restart network

/etc/init.d/network restart

8. Check your newly created ip.

Check the gateway:

route -n

Check the ip address:

ifconfig