How to permanently change the IP address of Ubuntu with CLI only?
8,285
Two (of many ways) to do it, say you want the new IP to be 192.168.80.10 with netmask 255.255.255 and your interface is eth0
$ sudo ifconfig eth0 192.168.80.10 netmask 255.255.255.0
or, with the newer ip
command, you remove the old address and add the new one:
$ sudo ip address del old.ip.address/netmask dev eth0
$ sudo ip address add 192.168.80.10/24 dev eth0
Author by
rahul Kushwaha
Updated on September 18, 2022Comments
-
rahul Kushwaha over 1 year
I have a ubuntu machine and want to change the IP address, the requirements are as follow:-
- using only cli to change the IP address, since the HW is not accessible and the script is changing the IP address through SSH, so it has to be the only cli
- The changes to be permanent, the IP address shouldn't be lost on restart
- This should be applicable to all the version of ubuntu
The ubuntu in question is a VM with the default static IP already configured can be accessed with the SSH.
Is there any way to change the IP address of ubuntu with the above requirement?
preferably it should be supported from version 14 - 20 (only stable build)
-
Eduardo Trápani almost 4 yearsHow did you get the original address, the one you are trying to change? DHCP, ifupdown, static, netplan ...
-
rahul Kushwaha almost 4 yearsit is snapshot of VM, hence IP is pre-configured, need to change that.
-
rahul Kushwaha almost 4 yearsyes, its static IP allocation
-
K7AAY almost 4 yearsTo start with, which release number? Different releases have different tools for us to recommend. Please click edit & add that to your question, so all facts we need are in the question. Please don't use Add Comment, since that's our one-way channel to you. All facts about your PC should go in the Question with edit as this is a Q&A site, not a general forum, so things work differently here.
-
rahul Kushwaha almost 4 yearswill it, instantly apply the IP address?
-
Eduardo Trápani almost 4 years@rahulKushwaha yes