How To Manually Assign A Static IP In Linux
People often forget the process for assigning a static IP address from the Linux command line. Most actually feel too intimidated by the process to commit it to memory, but it's actually very simple. Here's how to get networking all the way up in a matter of seconds using just three commands.
Step One: Set Your IP Address
# ifconfig eth0 192.168.1.5 netmask 255.255.255.0 up
Step 2: Set Your Default Gateway
# route add default gw 192.168.1.1
Step 3: Set Your DNS Server
# echo "nameserver 4.2.2.2" > /etc/resolv.conf
That's it.
Assuming you have valid addresses for yourself and your gateway (and you have a clear path the the Interweb) you're all set. Test by pinging someone.:
# ping google.com