How to change your IP address from the command line in Linux

It’s easy to change your IP address using a graphical user interface, but did you know that on Linux you can also change the IP address of your network card with a simple command from the command line?

This trick should work on all Debian-based Linux distributions, including Ubuntu. To start, type in ifconfig at the terminal prompt and then press Enter. This command lists all of the system’s network interfaces, so make a note of the name of the interface for which you want to change the IP address.

To change the settings, use the ifconfig command as well, this time with some additional parameters. The following command changes the network interface named “eth0” to 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

You can of course use any values. If you run ifconfig again, you will see that your interface has now adopted the new settings that you assigned to it.


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 standard gateway for the “eth0” interface to 192.168.0.253:

sudo route add default gw 192.168.0.253 eth0

To see your new setting you need to view the routing table. Enter the following command at the command prompt, then press Enter:

route -n

How to work with the network from the Linux terminal: 11 commands you need to know

That’s all you need to change your IP address from the terminal. If you’re interested in other great networking tools to use at the terminal, be sure to check out our guide on the topic.

Linux commands
Filestar · pv · cat · tac · chmod · grep · difference · sed · With · man · pushed · popd · fsck · Test disk · seq · fd · pandoc · CD · $ PATH · awk · join · jq · wrinkles · unique · Journalctl · tail · stat · ls · fstab · echo · fewer · chgrp · chown · rev · look · Strings · Type · rename · Postal code · unzip · assemble · ummount · To install · fdisk · mkfs · rm · rmdir · rsync · df · gpg · weather · Nano · mkdir · from · ln · Patch · Convert · rclon · Scraps · srm
Processesalias · screen · above · kind · renice · progress · strace · system · tmux · chsh · story · at · Batch · for free · which · dmesg · chfn · User mod · ps · chroot · xargs · tty · pinkie finger · lsof · vmstat · Time out · Wall · Yes sir · kill · sleep · sudo · it is · Time · groupadd · User mod · groups · lshw · switch off · start anew · Stop · switch off · passwd · lscpu · crontab · date · bg · fg
Networkingnetstat · Ring · Trace route · ip · ss · who is · fail2ban · bmon · she · finger · nmap · ftp · curl · wget · who · who am I · w · iptables · ssh-keygen · ufw

Best Linux Laptops for Developers and Enthusiasts

Related Posts