It's easy to change your IP address using a graphic interface, but did you know that Linux also lets you change your network card's IP address using a simple command from the command line?

This trick should work on all Debian-based Linux distros, including Ubuntu. To get started, type

        ifconfig
    

at the terminal prompt, and then hit Enter. This command lists all network interfaces on the system, so take note of the name of the interface for which you want to change the IP address.

image

To change the settings, you also use the ifconfig command, this time with a few additional parameters. The following command changes the network interface named "eth0" to use the IP address 102.168.0.1, and assigns the subnet mask 255.255.255.0:

sudo ifconfig eth0 192.168.0.1 netmask 255.255.255.0

image

You could, of course, substitute in whatever values you want. If you run ifconfig again, you will see that your interface has now taken on the new settings you assigned to it.

image

If you also need to change the Default Gateway used by the network interface, you can use the route command. The following command, for example, sets the default gateway for the "eth0" interface to 192.168.0.253:

sudo route add default gw 192.168.0.253 eth0

image

To see your new setting, you will need to display the routing table. Type the following command at the prompt, and then hit Enter:

route -n

image

Related: How to Work with the Network from the Linux Terminal: 11 Commands You Need to Know

That's all there is to changing your IP address from the terminal. If you're interested in other great networking tools you can use at the terminal, be sure to check out our guide to the subject.

Linux Commands

Files

tar · pv · cat · tac · chmod · grep ·  diff · sed · ar · man · pushd · popd · fsck · testdisk · seq · fd · pandoc · cd · $PATH · awk · join · jq · fold · uniq · journalctl · tail · stat · ls · fstab · echo · less · chgrp · chown · rev · look · strings · type · rename · zip · unzip · mount · umount · install · fdisk · mkfs · rm · rmdir · rsync · df · gpg · vi · nano · mkdir · du · ln · patch · convert · rclone · shred · srm · scp · gzip · chattr · cut · find · umask · wc · tr

Processes

alias · screen · top · nice · renice · progress · strace · systemd · tmux · chsh · history · at · batch · free · which · dmesg · chfn · usermod · ps · chroot · xargs · tty · pinky · lsof · vmstat · timeout · wall · yes · kill · sleep · sudo · su · time · groupadd · usermod · groups · lshw · shutdown · reboot · halt · poweroff · passwd · lscpu · crontab · date · bg · fg · pidof · nohup · pmap

Networking

netstat · ping · traceroute · ip · ss · whois · fail2ban · bmon · dig · finger · nmap · ftp · curl · wget · who · whoami · w · iptables · ssh-keygen · ufw · arping · firewalld

RELATED: Best Linux Laptops for Developers and Enthusiasts