Assign a static IP, DNS, Gateway with “ifconfig” and “route add”

Here is a quick way to assign a static IP, DNS and Default gateway in a RedHat / CentOS Linux machine. Some of these changes may not be persistent across reboots.

# ifconfig eth0 up
# ifconfig eth0 192.168.11.2 netmask 255.255.255.0 broadcast 192.168.11.255
# echo “nameserver 192.168.11.1” >> /etc/resolv.conf
# route add default gw 192.168.11.1

Additional Commands
ifconfig -a  #Lists all interfaces including disabled ones
ifconfig eth0 down  #Brings down the interface
ifconfig eth0 promisc  #Add promiscuous mode
ifconfig eth0 -promisc  #Remove promiscuous mode
ifconfig eth0 mtu 9000  #Change MTU to 9000, default is 1500
ifconfig eth0:0 192.168.11.3  #Add an alias, must be in same subnet range
ifconfig eth0:0  #Show alias information
ifconfig eth0:0 down  #Completely remove an alias
ifconfig eth0 hw ether AA:BB:CC:DD:EE:FF  #Change MAC address of the interface
route  #List the default gateway and routing table
route add default gw 192.168.11.1  #Add default gateway
route del default  #Delete the default gateway

SPONSOR:

This entry was posted in Linux and tagged , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *