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 netmask broadcast
# echo “nameserver” >> /etc/resolv.conf
# route add default gw

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  #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  #Add default gateway
route del default  #Delete the default gateway


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

Leave a Reply

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