How-To Geek

How to use the ip command on linux.

It is time to break up with ifconfig.

Quick Links

How the ip command works, using ip with addresses, display only ipv4 or ipv6 addresses, display information for a single interface, adding an ip address, deleting an ip address, using ip with network interfaces, starting and stopping links, using ip with routes, display information for a single route, adding a route, taken route, not taken root, key takeaways.

  • The ip command has replaced the older ifconfig command in modern versions of Linux.
  • The ip command allows you to configure IP addresses, network interfaces, and routing rules on the fly without rebooting.
  • Run "ip addr" in the Terminal to get your PC's local IP address.

You can configure IP addresses, network interfaces, and routing rules on the fly with the Linux ip command. We'll show you how you can use this modern replacement of the classic (and now deprecated) ifconfig .

With the ip command, you can adjust the way a Linux computer handles IP addresses, network interfaces controllers (NICs), and routing rules . The changes also take immediate effect — you don't have to reboot. The ip command can do a lot more than this, but we'll focus on the most common uses in this article.

The ip command has many subcommands, each of which works on a type of object, such as IP addresses and routes. There are, in turn, many options for each of these objects. It's this richness of functionality that gives the ip command the granularity you need to perform what can be delicate tasks. This isn't ax work — it calls for a set of scalpels.

We'll look at the following objects:

  • Address : IP addresses and ranges.
  • Link : Network interfaces, such as wired connections and Wi-Fi adapters.
  • Route : The rules that manage the routing of traffic sent to addresses via interfaces ( links ).

Obviously, you first have to know the settings you're dealing with. To discover which IP addresses your computer has, you use the ip command with the object address . The default action is show , which lists the IP addresses. You can also omit show and abbreviate address as "addr" or even "a."

The following commands are all equivalent:

ip address show

ip addr show

We see two IP addresses, along with a lot of other information. IP addresses are associated with network interface controllers (NICs). The ip command tries to be helpful and provides a bunch of information about the interface, too.

The first IP address is the (internal) loopback address used to communicate within the computer. The second is the actual (external) IP address the computer has on the local area network (LAN).

Let's break down all the information we received:

  • lo : The network interface name as a string.
  • <LOOPBACK,UP,LOWER_UP>: This is a loopback interface. It's UP , meaning it's operational. The physical networking layer (layer one) is also up.
  • mtu 65536: The maximum transfer unit. This is the size of the largest chunk of data this interface can transmit.
  • qdisc noqueue: A qdisc is a queuing mechanism. It schedules the transmission of packets. There are different queuing techniques called disciplines. The noqueue discipline means "send instantly, don't queue." This is the default qdisc discipline for virtual devices, such as the loopback address.
  • state UNKNOWN: This can be DOWN (the network interface is not operational), UNKNOWN (the network interface is operational but nothing is connected), or UP (the network is operational and there is a connection).
  • group default: Interfaces can be grouped logically. The default is to place them all in a group called "default."
  • qlen 1000: The maximum length of the transmission queue.
  • link/loopback: The media access control (MAC) address of the interface.
  • inet 127.0.0.1/8: The IP version 4 address. The part of the address after the forward-slash ( / ) is Classless Inter-Domain Routing notation (CIDR) representing the subnet mask. It indicates how many leading contiguous bits are set to one in the subnet mask. The value of eight means eight bits. Eight bits set to one represents 255 in binary, so the subnet mask is 255.0.0.0.
  • scope host: The IP address scope. This IP address is only valid inside the computer (the "host").
  • lo: The interface with which this IP address is associated.
  • valid_lft: Valid lifetime. For an IP version 4 IP address allocated by Dynamic Host Configuration Protocol (DHCP), this is the length of time the IP address is considered valid and able to make and accept connection requests.
  • preferred_lft: Preferred lifetime. For an IP version 4 IP address allocated by DHCP, this is the amount of time the IP address can be used with no restrictions. This should never be larger than the valid_lft value.
  • inet6 : The IP version 6 address, scope , valid_lft , and preferred_lft .

The physical interface is more interesting, as we'll show below:

  • enp0s3: The network interface name as a string. The "en" stands for ethernet, "p0" is the bus number of the ethernet card, and "s3" is the slot number.
  • <BROADCAST,MULTICAST,UP,LOWER_UP>: This interface supports broad- and multicasting , and the interface is UP (operational and connected). The hardware layer of the network (layer one) is also UP .
  • mtu 1500: The maximum transfer unit this interface supports.
  • qdisc fq_codel: The scheduler is using a discipline called "Fair Queuing, Controlled Delay." It's designed to provide a fair share of the bandwidth to all the traffic flows that use the queue.
  • state UP: The interface is operational and connected.
  • group default: This interface is in the "default" interface group.
  • link/ether: The MAC address of the interface.
  • inet 192.168.4.26/24: The IP version 4 address. The "/24" tells us there are 24 contiguous leading bits set to one in the subnet mask. That's three groups of eight bits. An eight-bit binary number equates to 255; therefore, the subnet mask is 255.255.255.0.
  • brd 192.168.4.255: The broadcast address for this subnet.
  • scope global: The IP address is valid everywhere on this network.
  • dynamic: The IP address is lost when the interface goes down.
  • noprefixroute: Do not create a route in the route table when this IP address is added. Someone has to add a route manually if he wants to use one with this IP address. Likewise, if this IP address is deleted, don't look for a route to delete.
  • enp0s3: The interface with which this IP address is associated.
  • valid_lft: Valid lifetime. The time the IP address will be considered valid; 86,240 seconds is 23 hours and 57 minutes.
  • preferred_lft: Preferred lifetime. The time the IP address will operate without any restrictions.
  • inet6: The IP version 6 address, scope , valid_lft , and preferred_lft .

If you want to limit the output to the IP version 4 addresses, you can use the -4 option, as follows:

If you want to limit the output to the IP version 6 addresses, you can use the -6 option, as follows:

If you want to see the IP address information for a single interface, you can use the show and dev options, and name the interface, as shown below:

ip addr show dev lo

ip addr show dev enp0s3

You can also use the -4 or -6 flag to further refine the output so you only see that in which you're interested.

If you want to see the IP version 4 information related to the addresses on interface enp0s3 , type the following command:

ip -4 addr show dev enp0s3

You can use the add and dev options to add an IP address to an interface. You just have to tell the ip command which IP address to add, and to which interface to add it.

We're going to add the IP address 192.168.4.44 to the enp0s3 interface. We also have to provide the CIDR notation for the subnet mask.

We type the following:

sudo ip addr add 192.168.4.44/24 dev enp0s3

We type the following to take another look at the IP version 4 IP addresses on this interface:

The new IP address is present on this network interface. We jump on another computer and use the following command to see if we can ping the new IP address :

ping 192.168.4.44

The IP address responds and sends back acknowledgments to the pings. Our new IP address is up and running after one simple ip command.

To delete an IP address, the command is almost the same as the one to add one, except you replace add with del , as shown below:

sudo ip addr del 192.168.4.44/24 dev enp0s3

If we type the following to check, we see the new IP address has been deleted:

You use the link object to inspect and work with network interfaces. Type the following command to see the interfaces installed on your computer:

ip link show

To see a single network interface, just add its name to the command, as shown below:

ip link show enp0s3

You can use the set option with either up or down to stop or start a network interface option. You also have to use sudo , as shown below:

sudo ip link set enp0s3 down

We type the following to take a look at the network interface:

The state of the network interface is DOWN . We can use the up option to restart a network interface, as shown below:

sudo ip link set enp0s3 up

We type the following to do another quick check on the state of the network interface:

The network interface was restarted, and the state is shown as UP .

With the route object, you can inspect and manipulate routes. Routes define to where network traffic to different IP addresses is forwarded, and through which network interface.

If the destination computer or device shares a network with the sending computer, the sending computer can forward the packet directly to it.

However, if the destination device is not directly connected, the sending computer forwards the packet to the default router. The router then decides where to send the packet.

To see the routes defined on your computer, type the following command:

Let's take a look at the info we received:

  • default: The default rule. This route is used if none of the other rules match what's being sent.
  • via 192.168.4.1: Routes the packets via the device at 192.168.4.1. This is the IP address of the default router on this network.
  • dev enp0s3: Use this network interface to send the packets to the router.
  • proto dhcp: The routing protocol identifier. DHCP means the routes will be determined dynamically.
  • metric 100: An indication of the preference of the route compared to others. Routes with lower metrics are preferentially used over those with higher metrics. You can use this to give preference to a wired network interface over a Wi-Fi one.

The second route governs traffic to the IP range of 169.254.0.0/16. This is a zero-configuration network , which means it tries to self-configure for intranet communication. However, you can't use it to send packets outside the immediate network.

The principle behind zero-configuration networks is they don't rely on DHCP and other services being present and active. They only need to see TCP/IP in order to self-identify to each of the other devices on the network.

Let's take a look:

  • 169.254.0.0/16: The range of IP addresses this routing rule governs. If the computer communicates on this IP range, this rule cuts in.
  • dev enp0s3: The network interface the traffic governed by this route will use.
  • scope link : The scope is link , which means the scope is limited to the network to which this computer is directly connected.
  • metric 1000 : This is a high metric and isn't a preferred route.

The third route governs traffic to the IP address range of 192.168.4.0/24. This is the IP address range of the local network to which this computer is connected. It's for communication across, but within, that network.

Let's break it down:

  • 192.168.4.1/24: The range of IP addresses this routing rule governs. If the computer communicates within this IP range, this rule triggers and controls the packet routing.
  • dev enp0s3: The interface through which this route will send packets.
  • proto kernel: The route created by the kernel during auto-configuration.
  • scope link: The scope is link , which means the scope is limited to the immediate network to which this computer is connected.
  • src 192.168.4.26: The IP address from which packets sent by this route originate.
  • metric 100: This low metric indicates a preferred route.

If you want to focus on the details of a particular route, you can add the list option and IP address range of the route to the command as follows:

ip route list 192.168.4.0/24

We just added a new network interface card to this computer. We type the following and see it's showing up as enp0s8 :

We'll add a new route to the computer to use this new interface. First, we type the following to associate an IP address with the interface:

sudo ip addr add 192.168.121.1/24 dev enp0s8

A default route using the existing IP address is added to the new interface. We use the delete option, as shown below, to delete the route and provide its details:

sudo ip route delete default via 192.168.4.1 dev enp0s8

We'll now use the add option to add our new route. The new interface will handle network traffic in the 192.168.121.0/24 IP address range. We'll give it a metric of 100; because it will be the only route handling this traffic, the metric is pretty much academic.

sudo ip route add 192.168.121.0/24 dev enp0s8 metric 100

Now, we type the following to see what it gives us:

Our new route is now in place. However, we still have the 192.168.4.0/24 route that points to interface enp0s8 — we type the following to remove it:

sudo ip route delete 192.168.4.0/24 dev enp0s8

We should now have a new route that points all traffic destined for IP range 192.168.121.0/24 through interface enp0s8 . It should also be the only route that uses our new interface.

We type the following to confirm:

The great thing about these commands is they're not permanent. If you want to clear them, just reboot your system. This means you can experiment with them until they work the way you want. And it's a very good thing if you make a terrible mess of your system — a simple reboot will restore order.

On the other hand, if you want the changes to be permanent, you have to do some more work. Exactly what varies depending on the distribution family, but they all involve changing config files.

This way, though, you can test-drive commands before you make anything permanent.

How to Encrypt Files in Linux? [6 Best Methods]

how to encrypt files in linux 4 best methods featured image

4 Effective Ways to Delete Multiple Keys in Redis CLI

4 effective ways to delete keys in redis cli featured image

How to View Linux File Timestamps? [3 Easy Methods]

how to see the timestamps of a file in linux 3 easy methods featured image

How to Get All Keys in Redis Using Command Line Interface? [2 Best Methods]

how to list all keys in redis using command line interface on ubuntu 2 best methods featured image

How to Change IP Address in Linux [3 Effective Methods]

how to change ip address in linux using command line

Reviewed by

Last updated: June 25, 2023

Expert verified

To change ip address in Linux, you can try these three methods:

  • Using the ifconfig Command: Change IP address through the command line.
  • Configuring IP Address via Network Manager: Change IP address using a graphical interface.
  • Using the ip Command: Change IP address with extensive network configuration capabilities.

Changing IP addresses in Linux requires careful attention to ensure a smooth transition. Follow best practices such as obtaining proper authorization, planning and documenting changes, verifying compatibility, and conducting thorough testing. By adhering to these practices, you can minimize disruptions, maintain system security, and seamlessly transition to the new IP address configuration.

Explore the guide below to learn different methods and best practices to change ip address in Linux.

IP addresses are unique identifiers assigned to devices connected to a network, enabling data transfer and communication. You might need to change IP address in Linux for various reasons, such as safeguarding your privacy, accessing geo-restricted content, troubleshooting network issues, or even experimenting with different network configurations.

In this ultimate guide, I will explore three effective methods to change IP address in Linux and four best practices to remember when changing the ip address. 

How to Change IP Address in Linux

To change IP address in Linux, you have options that suit your preferences. For advanced users and scripting, the ifconfig command provides command-line control. Network Manager offers a user-friendly graphical interface, while the ip command provides extensive network configuration capabilities.

1. Using the ifconfig Command

This method allows you to change your IP address through the command line, making it useful for advanced users and scripting purposes. Follow these steps to change your IP address using ifconfig:

  • Open a Terminal window.

opening terminal 10

  • Identify the network interface you want to modify by running the command: 
  • It will display a list of available network interfaces.

identify network interface you want to modify

  • Disable the network interface using: 
  • Replace the interface with the interface that you selected.

disabling network interface

  • Change the IP address using the command: 
  • This command will change the IP address.

changing ip address

  • Verify the changes by running ifconfig again.

verifying the changes

2. Configuring IP Address via Network Manager

Network Manager provides a user-friendly graphical interface for changing IP addresses, making it suitable for users who prefer a visual approach to network configuration. Here’s how you can change IP address in Linux using Network Manager’s graphical interface:

  • Open the Network Manager applet from the system tray or access it through the system settings.

opening system settings

  • Locate the network connection you want to modify and select it.

locating network to change ip address

  • Click on the IPv4 or IPv6 tab, depending on the type of address you wish to change.

choosing ip address type to change it

  • Choose the Manual option from the Method dropdown menu.

choosing manual method

  • Enter the desired IP address, subnet mask, gateway, and DNS servers, then click on the apply button.

entering desired ip address

  • The output will be:

changes are made

3. Using the ip Command

The ip command offers extensive network configuration capabilities, making it a powerful tool for advanced users who require fine-grained control over IP address changes. Follow these steps to change your IP address using the ip command:

  • Open a Terminal window and identify the network interface you wish to modify using the command: 
  • The command will show a list of network interfaces.

identifying network interface

  • Disable the network interface: 

Replace interface with interface name that you chose.

disable desired network interface

  • Change the IP address by executing the command: 
  • The command will change the ip address.

changing ip address of desired interface

  • Enable the network interface: 
  • The changes will look like this:

enabling network interface

Best Practices for Changing IP Address

Changing IP addresses in Linux requires careful attention to ensure a smooth transition and avoid potential issues. Following these best practices when changing IP addresses in Linux helps maintain system security, minimize downtime, and ensure a smooth transition to the new IP configuration. Here are four best practices to follow:

  • 🔒 Ensure Proper Authorization and Permission: Before changing your IP address, it is crucial to ensure that you have the necessary authorization and permission to do so. Modifying network settings often requires administrative privileges. Changing IP addresses without proper authorization can lead to network connectivity issues or violations of organizational policies. Always consult your network administrator or obtain the necessary permissions before proceeding to avoid potential complications or security breaches.
  • ⏰ Plan and Document Your Changes: Changing IP addresses should not be taken lightly. It is important to plan and document your changes to avoid confusion and ensure a smooth transition. Before making any modifications, create a clear plan outlining the steps and desired outcomes. Documenting the changes helps maintain an organized process record, making troubleshooting easier if any issues arise. Documentation is also a valuable reference for future network management or IP address reconfiguration.
  • 💡 Verify Compatibility and Impact: Verify the compatibility and potential impact of changing your IP address, especially if your network is integrated with other systems or services. Determine whether the IP address change will affect other components such as DNS, routing, or network services. Assess potential compatibility issues with existing devices, software, or network configurations. Identifying and addressing compatibility concerns beforehand can minimize disruptions and ensure a seamless transition to the new IP address without compromising other essential network functionalities.
  • 🔧 Test and Validate the New Configuration: Before implementing the new IP address configuration in a production environment, it is crucial to test and validate the changes thoroughly. Set up a test environment or use a sandbox network to simulate the configuration of the new IP address. Test network connectivity, services, and applications to ensure they function correctly with the new IP address. By conducting thorough testing, you can identify and address any issues or conflicts before deploying the changes to the live network. This proactive approach helps mitigate potential downtime or disruptions and ensures a smooth transition to the new IP address.

In a Nutshell

I have provided you with various methods to change IP address in Linux, including using the ifconfig command, modifying network configuration files, and utilizing the ip command. Alongside these methods, I have shared best practices to ensure a smooth and secure IP address change.

To deepen your knowledge, consider exploring related topics such as advanced network configuration , network security practices , or setting up a Virtual Private Network (VPN) for enhanced privacy and anonymity. Stay updated with the latest developments in Linux networking to ensure you stay ahead in managing IP addresses and optimizing your network connectivity.

Frequently Asked Questions

How do i revert to my original ip address after making changes.

If you wish to revert to your original IP address after making changes, simply follow the steps outlined in the respective method you used initially, but instead of entering a new IP address, use your initial IP configuration. For example, if you modified the IP address using the ifconfig command, open the Terminal and use sudo ifconfig interface original_ip_address netmask subnet_mask up . This will restore your original IP address and network settings.

Will changing the IP address affect other network settings?

Yes, changing the IP address can impact other network settings. DNS configuration is one of the critical network settings that can be affected. DNS (Domain Name System) translates domain names into IP addresses, allowing you to access websites using their domain names. When you change your IP address, it is important to ensure that the DNS settings are updated to reflect the new IP address, or else you may experience issues with domain name resolution.

Can changing the IP address help bypass geo-restrictions?

Yes, changing your IP address can be an effective method to bypass certain geo-restrictions. Changing your IP address, especially one associated with a different geographic location, can make it appear like you are accessing the internet from that particular region. This can help you bypass restrictions imposed by certain websites or online services that limit access based on geographical boundaries. By changing your IP address to one that allowed access, you can overcome these restrictions and gain access to content or services previously unavailable in your original location.

How can I automate the IP address change process in Linux?

To automate the IP address change process in Linux, you can utilize scripting and scheduling tools. You can automate the entire process by creating a script with the necessary commands to change the IP address. Save the script and grant it executable permissions. Then, you can use tools like cron , a time-based job scheduler, to schedule the execution of the script at specific intervals or during system startup. By configuring cron to run the script automatically, you eliminate the need for manual intervention, making the IP address change process in Linux seamless and automated.

how to change ip address in linux using command line

Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.

how to change ip address in linux using command line

Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article

How to find ip address in linux command line [5 easy methods], 3 effective methods to select all text in vim/vi, leave a reply cancel reply.

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

Save my name, email, and website in this browser for the next time I comment.

How to Get UUID in Linux [5 Best Methods]

how-to-find-uuid-in-linux-3-best-methods-featured-image

How to Ping on Discord on Linux? [4 Simple Methods]

how to ping on discord on linux 4 simple methods featured image

How to Display File Size in Linux in Human Readable Format

How to Display File Size in Linux in Human Readable Format featured image

4 Best Methods to Change or Set User Password in Linux

4 best methods to change or set user password in linux featured image

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

How to change ip address in ubuntu desktop through command line

In Ubuntu desktop 13.04 changing /etc/network/interfaces file don't change ip address or convert DHCP to static network interface configuration. after changing the file I tried

----------EDIT----------

I have connected to system with ssh.

  • command-line
  • network-manager

Necktwi's user avatar

  • How are you changing the IP when editing the` /etc/network/interfaces` file? –  Mitch Aug 21, 2013 at 11:46
  • @Mitch link –  Necktwi Aug 21, 2013 at 11:50
  • 1 You mean to say you edited that file but it doesn't have any effect? It doesn't change the IP address? –  Alaa Ali Aug 21, 2013 at 11:52
  • @Alaa i did sudo service networking restart –  Necktwi Aug 21, 2013 at 11:53

6 Answers 6

By default, Ubuntu (or Network Manager to be specific) ignores the /etc/network/interfaces file. To make the changes you made take effect, execute the following commands:

Assuming that wlan0 is the interface you are editing. Once you do that, wlan0 will come up with the settings you have under its stanza in /etc/network/interfaces .

Edit: since you're connected through SSH. You can try the following:

Edit /etc/NetworkManager/NetworkManager.conf and change ifdown managed to false :

  • How to restart the networking service?

Community's user avatar

  • if i use ifdown i will loose connection to the system. If it dont work there is no way to connect again. –  Necktwi Aug 21, 2013 at 12:10
  • i can try restarting the system but if static ip is not set i cant know its dynamic new ip –  Necktwi Aug 21, 2013 at 12:14
  • @neckTwi try my updated answer. Also, are you sure it's going to have a different IP? Usually, there's a lease period where, even if you restart the machine, it'll still get the same IP until the pre-defined lease period expires. But that depends of course, I'm just saying what's on my mind. –  Alaa Ali Aug 21, 2013 at 12:17
  • what does [ifupdown] managed=false mean? –  Necktwi Aug 21, 2013 at 12:20
  • If it is set to true, NetworkManager "manages" the interfaces mentioned in /etc/network/interfaces . If it's set to false, NetworkManager does not manage the interfaces mentioned there. –  Alaa Ali Aug 21, 2013 at 12:27

Try this. Just press Ctrl + Alt + T on your keyboard to open Terminal. When it opens, run the command(s) below:

This is done with the help of guntbert

Once done save and exit

add this line DHCP mode

Static mode

Once done save the file, and:

Mitch's user avatar

  • These aren't permanent changes. They'll be overridden when the computer restarts. –  Alaa Ali Aug 21, 2013 at 11:52
  • that dont survive system restart –  Necktwi Aug 21, 2013 at 11:52
  • Do you have a static or dynamic IP? –  Mitch Aug 21, 2013 at 11:57
  • @guntbert Is this better? Thanks :) –  Mitch Aug 21, 2013 at 16:49
  • This doesn't work (or no longer works). Ubuntu doesn't seem to care about /etc/network/interfaces . –  giusti Mar 12, 2017 at 13:39

You can change your ip address by using the following script:

Open terminal with Ctrl + Alt + t and type the following command:

Find eth0 section and setup IP address as follows:

Save and close the file. Once done, restart network:

Verify new IP address by using the following command :

Seth's user avatar

  • This is just a vehicle for your own websites; please disclose your affiliation to ip-details.com and Whoisxy.com , or don't link to these sites from all your posts . See the help center . –  Martijn Pieters Jun 19, 2014 at 11:31

I am posting this answer to give another dimension to the question and existing answers, not as a direct answer to the original question. Your IP will be lost at reboot. However, I think it's worth you understanding these commands, iproute2 package is the currently method of on-the-fly interface management via the CLI. Lots of people are still writing scripts using ifconfig for example.

I think it's worth noting the use of the iproute2 packages;

Show current IPs on all interface ( ip addr )

Add an IP address to my wireless interface ( ip addr add )

Show my IP addresses again, note the additional IP on wlan0 ( ip addr )

Show the link state of my interfaces ( ip link )

Delete this 2nd IP address from my wireless interface ( ip addr delete )

Show IP addresses just for wlan0 to check ( ip addr show wlan0 )

The same commands could have been used to remove my current IP, 172.22.0.221 then add another, but I would have lost connectivity, which I can't right now. Below are those commands though, after which I would also need to add a new default route route;

Baldrick's user avatar

From t he detailed instructions on this site :

  • disable the graphical management of your network connection in /etc/NetworkManager/NetworkManager.conf
  • Gather the information for the static IP (interface, IP to be used, default gateway, subnet,DNS)
  • Modify /etc/network/interfaces to include the information above.
  • Restart networking and network-manager services

steampowered's user avatar

This is the right way to do it.

lewis4u's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged command-line networking network-manager ..

  • The Overflow Blog
  • Between hyper-focus and burnout: Developing with ADHD
  • Featured on Meta
  • Our Partnership with OpenAI
  • Imgur image URL migration: Coming soon to a Stack Exchange site near you!

Hot Network Questions

  • This might be habitual use but grammatically incorrect
  • How did White lose all their pieces?
  • My master's supervisor and paper co-author is not willing to give a letter of recommendation for PhD admissions?
  • What is this fuzzy green plant with spikes? (UK gardening)
  • Why do larger mass stars form quicker?
  • A question about circularly polarized light
  • Hash as filename to protect data
  • Which cognitive psychology findings are solid, that I can use to help my students?
  • Sample size and coefficient of variation
  • Short story in which a driver picks up hitchhikers who each try to kill him for political reasons
  • tcolorbox and logic formats
  • When to use Tanh?
  • Is it a bad idea to design a purposefully inconsistent magic system?
  • Can you draw these figures?
  • Can I cite the results from my unpublished manuscript which is included in my PhD thesis?
  • Bug Byte puzzle from Jane Street
  • I think I don't truly understand Cauchy's Integral theorem
  • How to use already existing bolts width to hang a floating shelf that has holes of different spacing?
  • Why didn't the 70 elders prophesy again
  • Name of (90’s?) movie or tv that had an alien scorpion creature that attaches to a forearm as a weapon/tool?
  • How to draw such a sphere with mesh
  • Meaning for chromatography terms linear velocity and volume flow rate
  • Java interpreter
  • How would humans on Earth detect a Shkadov thruster on other side of the Milky Way Galaxy?

how to change ip address in linux using command line

Select Your Language

How do i change the ip address/netmask and hostname on the command line without rebooting the machine.

Here are some example configuration files:

/etc/sysconfig/network

/etc/sysconfig/network-scripts/ifcfg-eth0

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content

Quick Links

  • Subscriptions
  • Support Cases
  • Customer Service
  • Product Documentation
  • Contact Customer Portal
  • Customer Portal FAQ
  • Log-in Assistance
  • Trust Red Hat
  • Browser Support Policy
  • Accessibility
  • Awards and Recognition

Related Sites

  • developers.redhat.com
  • connect.redhat.com
  • cloud.redhat.com

Systems Status

  • Red Hat Subscription Value
  • About Red Hat
  • Red Hat Jobs

Red Hat legal and privacy links

  • Contact Red Hat
  • Red Hat Blog
  • Diversity, equity, and inclusion
  • Cool Stuff Store
  • Red Hat Summit
  • Privacy statement
  • Terms of use
  • All policies and guidelines
  • Digital accessibility

Formatting Tips

Here are the common uses of Markdown.

Request a English Translation

Generating machine translation.

Set static IP in Ubuntu using Terminal

Everything you need to know about setting static IP on an Ubuntu machine using the command line.

Dec 5, 2022 — Pratham Patel

Normally, the router's DHCP server handles assigning the IP address to every device on the network, including your computer.

The DHCP server may also give you a new IP address occasionally. This could cause a problem if you have a home lab or server setup that works on a fixed IP address.

You need to set a static IP address on your Ubuntu system to avoid problems.

Step 1: Identify the correct network interface

The first step is always to know the name of your network interface.

"But why?" you might ask. That is because since Ubuntu 20.04, the network interfaces are named using predictable network interface names . This means your one and only ethernet interface will not be named 'eth0'.

Ubuntu Server and Ubuntu Desktop use different renderers for 'netplan', they are 'systemd-networkd' and 'NetworkManager', respectively. So let's go over their differences.

Ubuntu Server

To see available network interfaces on Ubuntu Server, run the following command:

Doing so will show a similar result:

The output enumerates network interfaces with numbers.

From this, I can see that the ethernet interface is 'enp1s0'.

Ubuntu Desktop

The advantage (at least in my opinion) of having Ubuntu Desktop is having NetworkManager as the renderer for netplan .

It has a pretty CLI output :)

Run the following command to view the available network interfaces:

That will give you the device name, type, state and connection status.

Here is what it looks like on my computer:

This is more readable at first glance. I can make out that my ethernet interface is named 'enp1s0'.

how to change ip address in linux using command line

Step 2: See current IP address

Now that you know which interface needs to be addressed, let us edit a file .

Before I change my IP address/set a static one, let us first see what my current IP address is .

Nice! But let's change it to '192.168.122.128' for demonstration purposes.

Step 3: See the gateway

A gateway is a device that connects different networks (basically what your all-in-one router is). To know the address of your gateway, run the following command:

The gateway address will be on the line that begins with "default via".

Below is the output of running the ip command on my computer:

On the line that starts with "default via", I can see that my gateway address '192.168.122.1'

Make a note of your gateway address.

Step 4: Set static IP address

Now that you have detail like interface name and gateway address, it is time to edit a config file.

Step 4-A: Disable cloud-init if present

The easiest way to know if cloud-init is present or not is to check if there is a package with that name.

Run the following command to check:

If you get an outupt, you have 'cloud-init' installed.

Now, to disable could-init, create a new file inside the /etc/cloud/cloud.cfg.d directory. The name does not matter, so I will call it '99-disable-cloud-init.cfg'.

Add the following line to it:

Please reboot your Ubuntu system now so that cloud-init does not interfere when we set our static IP address in the next step. :)

Back to Step 4

Once the 'cloud-init' related configuration is complete, we must now edit the netplan configuration to add our static IP address.

Go to the /etc/netplan directory. It is better if there is one file (easier to know which one to edit), but in some cases, there might also be more than one file with the extension '.yml' or '.yaml'.

When in doubt, grep for the name of your network interface. Use the following command if you are not comfortable with grep:

Since the name of network interface for my ethernet is 'enp1s0', I will run the following command:

running this command shows that the file I am looking for is '00-installer-config.yaml'. So let us take a look at it.

You might have noticed a line that says 'ethernet' and our network interface name under that. Under this is where we configure our 'enp1s0' network interface.

Since we do not want DHCP assigned IP address, let us change that field from true to no .

Add a field called addresses . Write the IP address you wish to assign your computer along with the network prefix. So I will write 192.168.122.128/24 in the addresses field.

Finally, we also need to specify DNS nameservers. For that, create a new field called nameservers and under that, create a field called addresses which contains the IP address for your DNS servers . I used Cloudflare's DNS servers but you can use whatever you want.

This is what my '00-installer-config.yaml' file looks like after editing it to my liking.

To apply the settings, run the following command:

This will take only a few seconds, and the IP address will be updated once it is done.

You can check the IP address using the hostname -I command.

Perfect! The IP address has now changed successfully.

how to change ip address in linux using command line

I know that it feels complicated but this is the proper procedure when you are trying to assign static IP via the command line in Ubuntu.

Let me know if you are stuck at some point or encounter any technical issues.

Pratham Patel

Fell in love with Ubuntu the first time I tried it. Been distro-hopping since 2016.

On this page

  • Command Line Interface (CLI)
  • Denial-of-Service Attack (DoS)
  • Desktop Managers
  • Linux Administration
  • Virtual Private Network (VPN)
  • Wireless LAN (Wi-Fi)
  • Privacy Policy

blackMORE Ops Learn one trick a day ….

Setup dhcp or static ip address from command line in linux.

March 26, 2015 Command Line Interface (CLI) , How to , Linux , Linux Administration , Networking 25 Comments

This guide will guide you on how to setup DHCP or static IP address from command Line in Linux. It saved me when I was in trouble, hopefully you will find it useful as well. In case you’ve only got Wireless, you can use this guide to connect to WiFi network from command line in Linux .

Note that my network interface is eth0 for this whole guide. Change eth0 to match your network interface.

Static assignment of IP addresses is typically used to eliminate the network traffic associated with DHCP/DNS and to lock an element in the address space to provide a consistent IP target.

Step 1 : STOP and START Networking service

Some people would argue restart would work, but I prefer STOP-START to do a complete rehash. Also if it’s not working already, why bother?

Step 2 : STOP and START Network-Manager

If you have some other network manager (i.e. wicd, then start stop that one).

Just for the kicks, following is what restart would do:

Step 3 : Bring up network Interface

Now that we’ve restarted both networking and network-manager services, we can bring our interface eth0 up. For some it will already be up and useless at this point. But we are going to fix that in next few steps.

The next command shows the status of the interface. as you can see, it doesn’t have any IP address assigned to it now.

Step 4 : Setting up IP address – DHCP or Static?

Now we have two options. We can setup DHCP or static IP address from command Line in Linux. If you decide to use DHCP address, ensure your Router is capable to serving DHCP. If you think DHCP was the problem all along, then go for static.

Again, if you’re using static IP address, you might want to investigate what range is supported in the network you are connecting to. (i.e. some networks uses 10.0.0.0/8, some uses 172.16.0.0/8 etc. ranges). For some readers, this might be trial and error method, but it always works.

Step 4.1 – Setup DHCP from command Line in Linux

Assuming that you’ve already completed step 1,2 and 3, you can just use this simple command

The first command updates /etc/network/interfaces file with eth0 interface to use DHCP.

The next command brings up the interface.

With DHCP, you get IP address, subnet mask, broadcast address, Gateway IP and DNS ip addresses. Go to step xxx to test your internet connection.

Step 4.2 – Setup static IP, subnet mask, broadcast address in Linux

Use the following command to setup IP, subnet mask, broadcast address in Linux. Note that I’ve highlighted the IP addresses in red . You will be able to find these details from another device connected to the network or directly from the router or gateways status page. (i.e. some networks uses 10.0.0.0/8, some uses 172.16.0.0/8 etc. ranges)

Next command shows the IP address and details that we’ve set manually.

Because we are doing everything manually, we also need to setup the Gateway address for the interface. Use the following command to add default Gateway route to eth0 .

We can confirm it using the following command:

Step 4.3 – Alternative way of setting Static IP in a DHCP network

If you’re connected to a network where you have DHCP enabled but want to assign a static IP to your interface, you can use the following command to assign Static IP in a DHCP network, netmask and Gateway.

At this point if your network interface is not up already, you can bring it up.

Step 4.4 –  Fix missing default Gateway

Looks good to me so far. We’re almost there.

Try to ping http://google.com/ (cause if www.google.com is down, Internet is broken!):

Step 5 : Setting up nameserver / DNS

For most users step 4.4 would be the last step. But in case you get a DNS error you want to assign DNS servers manually, then use the following command:

This will add Google Public DNS servers to your resolv.conf file. Now you should be able to ping or browse to any website.

Losing internet connection these days is just painful because we are so dependent on Internet to find usable information. It gets frustrating when you suddenly lose your GUI and/or your Network Manager and all you got is either an Ethernet port or Wireless card to connect to the internet. But then again you need to memorize all these steps.

I’ve tried to made this guide as much generic I can, but if you have a suggestion or if I’ve made a mistake, feel free to comment. Thanks for reading. Please share & RT.

Enabling AMD GPU for Hashcat on Kali Linux: A Quick Guide

Enabling AMD GPU for Hashcat on Kali Linux: A Quick Guide

If you’ve encountered an issue where Hashcat initially only recognizes your CPU and not the …

Boot Ubuntu Server 22.04 LTS from USB SSD on Raspberry Pi 4

Boot Ubuntu Server 22.04 LTS from USB SSD on Raspberry Pi 4

This is a guide for configuring Raspberry Pi4 to boot Ubuntu from external USB SSD …

25 comments

' src=

Just wanted to say, your guides are amazing and should be included into kali’s desktop help manual. Thanks for your awesome work!

' src=

Hi Matt, That’s very kind, thank you. I’m happy that my little contributions are helping others. Cheers, -BMO

' src=

I’ve gone through the steps listed in Step 4.2 and when I check my settings are correct, until I reboot. After I reboot all my settings have reverted back to the original settings. Any ideas?

' src=

The only problem with this is that nowadays Linux machines aren’t always shipped with the tools you use. They are now shipped with the systemd virus so the whole init.d doens’t work anymore and ifconfig isn’t shipped on a large number of distro’s.

Hi, The intention was to show what to do when things are broken badly. In my case, I’ve lost Network Manager and all of Gnome Desktop. I agree this is very old school but I’m sure it’s better than reinstalling. Not sure what distro you’re talking about. I use Debian based Kali (and Debian Wheezy), CentOS(5,6,7) and Ubuntu for work, personal and testing. ifconfig is present is every one of them. ifconfig also exists in all variants of server distro, even in all Big-IP F5’s or CheckPoint Firewalls. Hope that explains my inspiration for this article. Cheers, -BMO

' src=

Hi , I want to say Thank you for your Guide, it’s very useful. and want to add another method for Step 5 : Setting up nameserver / DNS: add nameserver directly to resolv.conf file

nano /etc/resolv.conf

Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)

DO NOT EDIT THIS FILE BY HAND — YOUR CHANGES WILL BE OVERWRITTEN

nameserver 8.8.8.8 nameserver 8.8.4.4 search Home

' src=

nano or vi is not requiered, use “printf” instead “echo”… e.g:

printf “nameserver 8.8.8.8\nnameserver 8.8.4.4\n” >> /etc/resolv.conf

double-check with:

grep nameserver /etc/resolv.conf

' src=

Hey I’m new to VM my eth0 inet addr is 10.0.02.15 but every video I watch their inet addr always starts with 192. I was wondering what I can do to change my inet addr to start with 192. Is this guide a solution

Hi Billy Bob, Is 10.x address coming from VBox internal or from your router? You possibly selected Bridged network. Try juggling between Bridged and NAT. Also look up VBox IP addressing in Google. Cheers -BMO

' src=

Please help, I’ve done all these steps and still I don’t have internet connection with bridged adapter. When I set NAT I have internet connection but with bridged adapter i don’t. I checked with ifconfig eth0 command and I have ip, netmask and broadcast ip. What could be the problem?

' src=

Excellent guide. I haven’t been using any debian based linux distros in a while and forgot where the entries go manually. I was actually kind of surprised how long it took to find your page in google, there is a lot of pages that don’t actually answer the question, but yours was spot on.

' src=

I did all the commands but my IP address doesn’t show up, and now my internet server on Linux iceweasel is down. It’s telling me that “Server not found” I really need help.

' src=

Hi Blackmoreops Thanks for the tutorial. I do have a question tho, in kalisana, I have followed your advice step by step to configure a static ip on my kali VM. But when I check with ifconfig, I still get the ip assigned by my modem? I run the kali vm on fedora 22 host… Is there a way around this? Regards Adexx

' src=

Hey Blackmoreops, Thanks for the great article. Being a total NOOB, I’m wondering if these are the last steps in getting my correct lab setting to enumerate De-Ice 1.100 with nmap. My current setting on Kali 2016 machine are: add:192.168.1.5 , mask: 255.255.255.0, default gw 192.168.1.1. Both machine set to NAT in Virtualbox 5. I’ve tried numerous scans ie., ping, list proctocol verify, and stealth and I’m unable to find any open ports. Help!!!!!!!

Best Regards. C

' src=

i tried on my kali linux but i lost my internet connection

' src=

hello everyone i have got problem on my kali linux with internet. Kali is connected to my wifi but iceweasel can’t open any site. Can you help me solve this problem please ?

' src=

check mtu and DNS

' src=

Followed through all the steps, and it worked. Then I restarted the router, and everything is back to the earlier configuration?

' src=

thanks for tutorial.bu how change the ip that blocked by google :D

' src=

Hello sorry but wasnt able to configure my network. I installed kali into my hdd and im using it as my main OS on this pc(idk if thats recommended or not) . I am curently connected to the internet with an ethernet cable and somehow in th top-right corner it says that is curently connected but when i try to open ice weasel i get a message that tells me “server not found” can someone please tell me how to fix this issue and also i followed your tutorial until the end but i had trouble in the end because i get this message bash: /etc/resolv.conf: no such file or directory . If you can help me i would be so gratefull. Sorry for butchering the english language and its grammar

' src=

Sir, How can we change or spoof dns server in kali Linux.

' src=

I can’t get my static IP address to ping google.

This is what I am trying to do:

ping google.com using a server created with static IP address using Linux Redhat VM Ware,

please help!

' src=

For setting up DHCP using the Command : ifconfig eth0 inet dhcp Also works

For setting up DHCP using command : ifconfig eth0 inet dhcp Also works

Leave your solution or comment to help others. Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed .

Discover more from blackMORE Ops

Subscribe now to keep reading and get access to the full archive.

Type your email…

Continue reading

Privacy Policy on Cookies Usage

Some services used in this site uses cookies to tailor user experience or to show ads.

How to Configure Static IP Address on Ubuntu 24.04 (Desktop)

In this article, we will show you how to configure static ip address on Ubuntu 24.04 desktop step by step.

When you want a persistent IP address on your Ubuntu 24.04 desktop, then you must a configure a static IP address. Whenever we install Ubuntu then DHCP is enabled by default, and it will try to fetch the IP address from DHCP server if it is available over the network.

In Ubuntu Desktop 24.04, there are two ways to configure static IP address:

  • Graphical User Interface
  • Command Line

We will cover both the methods in this article.

Prerequisites

  • Pre-Install Ubuntu 24.04
  • Regular user with sudo rights
  • Basic understanding of networks

Configure Static IP Address on Ubuntu 24.04 Using GUI

Login to your desktop, click on the network icon and then choose Wired option as shown below:

Wired-Network-Settings-Ubuntu-24-04

We will get the following window, click on “ gearbox” icon

Gearbox-Icon-Ubuntu-24-04-Network-WiredSettings

Go to IPv4 tab, there you will see that DHCP is enabled for automatic IP allocation.

Automatic-DHCP-Option-Ubuntu-24-04-Network-Settings-GUI

Choose Manual option to configure static IP address and specify IP details (IP address, netmask, gateway and DNS IP) as show below:

Note: Change the IP details that suits to your network

Configure Static IP Address On Ubuntu 24.04

Click on Apply .

Next, disable and enable the interface to make above changes into effect.

Above screen confirms that we have successfully configured static IP address on our Ubuntu 24.04 desktop.

Configure Static IP Address on Ubuntu 24.04 Using Command Line

We can use netplan utility and its configuration file to assign the static ip on the interface (like ep0s3 or eth0).

Netplan configuration file are placed in /etc/netplan directory. Under this directory there should be a file with name 01-netcfg.yaml , 50-cloud-init.yaml or may be else depending on your environment.

Netplan-Configuration-file-Ubuntu-24-04-Desktop

Edit netplan configuration file, in our case it is 01-netcfg.yaml

save and close the file.

Note: In above file, replace the IP address details and interface according to your setup. We have also used renderer as “ NetworkManager ” which instructs netplan to use NetworkManager as its backend. It is used for desktops and for the servers and headless environments use “ networkd ” instead of NetworkManager.

Configure Static IP Address On Ubuntu 24.04 Command Line

Set the permission on this file using chmod command,

To make above changes into the affect, run below netplan apply command.

Next, verify the IP address and network connectivity.

Verify-IP-Details-Ubuntu-24-04-Desktop

Perfect, output above shows that we have successfully configure static ip address using netplan utility.

That’s all from this article. We hope you have found it informative and useful, feel free to post your queries and feedback in below comments section.

Read Also : How to Install Git on Ubuntu 24.04

Leave a Comment Cancel reply

  • Trending Now
  • Foundational Courses
  • Data Science
  • Practice Problem
  • Machine Learning
  • System Design
  • DevOps Tutorial
  • How to Find Your Computer’s Serial Number?
  • How to Find Computer Name?
  • How To Find Your Router's IP through the Control Panel?
  • How to Find Your Mac Address?
  • How to Find Your IP Address on Windows?
  • How to Calculate Number of Host in a Subnet?
  • How to Find Your IP Address?
  • Introduction of Variable Length Subnet Mask (VLSM)
  • How to Find Your IP Address in Linux | ifconfig Command
  • How to Find Your MAC Address in Windows 11?
  • Java program to find IP address of your computer
  • How To See the IP Address of a URL?
  • Finding Network ID of a Subnet (using Subnet Mask)
  • How do Packets Find a Computer in a Network?
  • How to Calculate a Subnet Mask from IP Address?
  • How to Make Computer Lab in Packet Tracer?
  • How to Find Network IP Address of Computer Using Computer Name?
  • C Program to find IP Address, Subnet Mask & Default Gateway
  • How Many Ways to Find Your IP Address?

How to Find the Subnet Mask of Your Computer?

Welcome to today’s tech tips guide to find the subnet mask of your computer. Like your IP address, a subnet mask helps identify devices on a local network. To connect to a network and use internet resources, a computer user must have the idea of a subnet mask. In this article, we will learn the simplest method to find a subnet number.

Before we begin the methods, let’s first understand what a subnet mask is. After that, we’ll learn to find the subnet mask on your computer in Windows, Mac, and Linux using different methods.

What is a Subnet Mask?

In your home network, all devices have different IP addresses but share some similarities. If you consider an example of a house network. All device’s addresses start with ‘192.168.1,’ but the last part of the address (octet) is different.

The part of the address is divided into network ID ( same across all devices) and host ID (unique to each device). This is where the role of the subnet comes in, Different networks can have different sizes for these networks and host portions.

Must Check: Subnet Mask Cheat Sheet – Beginner to Advanced!

Most home networks have a subnet mask of ‘255.255.255.0.’ Basically, the way it works is explained below with a sample example.

  • The octets that are ‘255’ represent the network portion.
  • The octets that are ‘0’ represent the host portion.

For example, if a network has an IP address of 10.10.1.X and a subnet mask of ‘255.255.0.0,’ the first two octets (10.10) are the network portion, and the last two octets (1.X) are the host portion.

How to Find Subnet Mask in a Windows PC?

Method 1: find subnet mask using command prompt.

Step 1: Type Cmd in the search and open the Command Prompt.

Find-Subnet-Mask-in-a-Windows-PC_1

Step 2: Type IP configuration command mentioned below and press Enter

Find-Subnet-Mask-in-a-Windows-PC

The ipconfig command displays the network configuration and other network-related information as shown in the figure.

Step 3: Scroll down to Look for the ‘Subnet Mask’ entry under the network adapter information

Find-Subnet-Mask-in-a-Windows-PC_2

Method 2: Find Subnet Mask Using Control Panel

Step 1: Type control in the search and open the Control Panel.

Find-Subnet-Mask-in-a-Windows-PC_3

Step 2: Click on Network and Internet.

Find-Subnet-Mask-in-a-Windows-PC_4

Step 3: Click on Network and Sharing Center.

Find-Subnet-Mask-in-a-Windows-PC_5

Step 4: Click on the network connection you want to check (as shown below).

Find-Subnet-Mask-in-a-Windows-PC_6

Step 5: Click the Details button

Find-Subnet-Mask-in-a-Windows-PC_7

Your subnet mask will be listed under the Network Connection Details ( as shown below).

Find-Subnet-Mask-in-a-Windows-PC_8

Method 3: Calculate a Subnet Mask from the IP Address.

In cases where you can’t access command line or control panel, you can determine the subnet mask using the IP address itself by identifying the network portion and host portion of the IP address. For detailed steps, refer to, check How do I Find Subnet Mask for an IP Address?

How to Find Subnet Mask in a macOS?

Step 1: Click on the Apple icon and Go to System Preferences > Network

Step 2: Select the network connection you want to check

Step 3: Click the Advanced button at the bottom.

Step 4: Go to TCP/IP tab section, your subnet mask will be mentioned there

How to Find Subnet Mask in a Linux?

Step 1: Press Ctrl + Alt + T to open the Linux Terminal

Step 2: Type ifconfig and press Enter

Step 3: Now, Find the subnet mask. The subnet mask usually starts with 255 and is labeled as ‘Mask.’

The subnet mask is important because it facilitates communication between devices within the same network. By these methods, you can determine the subnet mask of your specific operating system or by using an online subnet calculator. Another way is to get and install a third-party tool to identify your PC’s subnet mask.However, using third-party software is not recommended and will just occupy storage on your device.

How to Find the Subnet Mask of Your Computer – FAQs

How is subnet mask different from ip address.

A subnet is a logical subdivision of an IP address. One portion identifies the computer being used as the host, while the other portion identifies the network it is connected to.

Can I change subnet mask of my computer?

It is possible to modify your computer’s subnet mask; however, if you do it wrong, your network connection may be disrupted. To prevent connectivity problems, verify the new subnet mask one more time.

How to calculate subnet mask using subnet calculators?

You can calculate subnet mask using online subnet calculators. Just search online subnet calculator on your browser and choose any reliable subnet calculator, Input your IP address into the calculator. It will then provide you with the subnet mask and other related information network addresses, host ranges, and IP class etc.

Please Login to comment...

Similar reads.

  • Computer Networks-IP Addressing

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

Change the hostname of your AL2 instance

When you launch an instance into a private VPC, Amazon EC2 assigns a guest OS hostname. The type of hostname that Amazon EC2 assigns depends on your subnet settings. For more information about EC2 hostnames, see Amazon EC2 instance hostname types in the Amazon EC2 User Guide for Linux Instances .

A typical Amazon EC2 private DNS name for an EC2 instance configured to use IP-based naming with an IPv4 address looks something like this: ip-12-34-56-78.us-west-2.compute.internal , where the name consists of the internal domain, the service (in this case, compute ), the region, and a form of the private IPv4 address. Part of this hostname is displayed at the shell prompt when you log into your instance (for example, ip-12-34-56-78 ). Each time you stop and restart your Amazon EC2 instance (unless you are using an Elastic IP address), the public IPv4 address changes, and so does your public DNS name, system hostname, and shell prompt.

This information applies to Amazon Linux. For information about other distributions, see their specific documentation.

Change the system hostname

If you have a public DNS name registered for the IP address of your instance (such as webserver.mydomain.com ), you can set the system hostname so your instance identifies itself as a part of that domain. This also changes the shell prompt so that it displays the first portion of this name instead of the hostname supplied by AWS (for example, ip-12-34-56-78 ). If you do not have a public DNS name registered, you can still change the hostname, but the process is a little different.

In order for your hostname update to persist, you must verify that the preserve_hostname cloud-init setting is set to true . You can run the following command to edit or add this setting:

If the preserve_hostname setting is not listed, add the following line of text to the end of the file:

To change the system hostname to a public DNS name

Follow this procedure if you already have a public DNS name registered.

For AL2: Use the hostnamectl command to set your hostname to reflect the fully qualified domain name (such as webserver.mydomain.com ).

For Amazon Linux AMI: On your instance, open the /etc/sysconfig/network configuration file in your favorite text editor and change the HOSTNAME entry to reflect the fully qualified domain name (such as webserver.mydomain.com ).

Reboot the instance to pick up the new hostname.

Alternatively, you can reboot using the Amazon EC2 console (on the Instances page, select the instance and choose Instance state , Reboot instance ).

Log into your instance and verify that the hostname has been updated. Your prompt should show the new hostname (up to the first ".") and the hostname command should show the fully-qualified domain name.

To change the system hostname without a public DNS name

For AL2: Use the hostnamectl command to set your hostname to reflect the desired system hostname (such as webserver ).

For Amazon Linux AMI: On your instance, open the /etc/sysconfig/network configuration file in your favorite text editor and change the HOSTNAME entry to reflect the desired system hostname (such as webserver ).

Open the /etc/hosts file in your favorite text editor and change the entry beginning with 127.0.0.1 to match the example below, substituting your own hostname.

You can also implement more programmatic solutions, such as specifying user data to configure your instance. If your instance is part of an Auto Scaling group, you can use lifecycle hooks to define user data. For more information, see Run commands on your Linux instance at launch and Lifecycle hook for instance launch in the AWS CloudFormation User Guide .

Change the shell prompt without affecting the hostname

If you do not want to modify the hostname for your instance, but you would like to have a more useful system name (such as webserver ) displayed than the private name supplied by AWS (for example, ip-12-34-56-78 ), you can edit the shell prompt configuration files to display your system nickname instead of the hostname.

To change the shell prompt to a host nickname

Create a file in /etc/profile.d that sets the environment variable called NICKNAME to the value you want in the shell prompt. For example, to set the system nickname to webserver , run the following command.

Open the /etc/bashrc (Red Hat) or /etc/bash.bashrc (Debian/Ubuntu) file in your favorite text editor (such as vim or nano ). You need to use sudo with the editor command because /etc/bashrc and /etc/bash.bashrc are owned by root .

Edit the file and change the shell prompt variable ( PS1 ) to display your nickname instead of the hostname. Find the following line that sets the shell prompt in /etc/bashrc or /etc/bash.bashrc (several surrounding lines are shown below for context; look for the line that starts with [ "$PS1" ):

Change the \h (the symbol for hostname ) in that line to the value of the NICKNAME variable.

(Optional) To set the title on shell windows to the new nickname, complete the following steps.

Create a file named /etc/sysconfig/bash-prompt-xterm .

Make the file executable using the following command.

Open the /etc/sysconfig/bash-prompt-xterm file in your favorite text editor (such as vim or nano ). You need to use sudo with the editor command because /etc/sysconfig/bash-prompt-xterm is owned by root .

Add the following line to the file.

Log out and then log back in to pick up the new nickname value.

Change the hostname on other Linux distributions

The procedures on this page are intended for use with Amazon Linux only. For more information about other Linux distributions, see their specific documentation and the following articles:

How do I assign a static hostname to a private Amazon EC2 instance running RHEL 7 or Centos 7?

Warning

To use the Amazon Web Services Documentation, Javascript must be enabled. Please refer to your browser's Help pages for instructions.

Thanks for letting us know we're doing a good job!

If you've got a moment, please tell us what we did right so we can do more of it.

Thanks for letting us know this page needs work. We're sorry we let you down.

If you've got a moment, please tell us how we can make the documentation better.

IMAGES

  1. How to get IP Address in Linux using Command terminal

    how to change ip address in linux using command line

  2. How To Change IP Address with Terminal on Linux

    how to change ip address in linux using command line

  3. How to change IP address in Linux by command line

    how to change ip address in linux using command line

  4. Set IP Address in Linux

    how to change ip address in linux using command line

  5. How to Change IP Address in Linux

    how to change ip address in linux using command line

  6. How to Change IP Address in Linux

    how to change ip address in linux using command line

VIDEO

  1. CentOS 7 Change Network Interface Name From enp0* To eth0

  2. How do we create a LIVE USB on LINUX? (using command line "dd")

  3. How to change your Windows 2025 IP address using the GUI PowerShell and Command Lines

  4. How to configure a static IP address for WiFi Network on Kali Linux

  5. How to Set A Static IP Address on Linux

  6. How to set static ip address using GUI in RHEL 8

COMMENTS

  1. How to Change IP Address in Linux

    The ip command is available on most Linux distributions. For setting an IP address, use it like this: ip addr add [ip_address] dev [interface] For example, add an IP address to the eth1 interface as: sudo ip addr add 192.168.56.21/24 dev eth1. You now have two IP addresses: one from the old configuration and one from the new command:

  2. 3 Ways to change ip address in Linux

    Open the terminal application. List the current IP addresses for all network interfaces with command ifconfig -a. Take the network interface down with command: ifconfig <interface> down. Change the IP address with command ifconfig <interface> <ip address> <netmask>. Press Enter to run the command.

  3. How To Change IP Address on Linux

    In order to change your IP address, edit the Network Manager configuration file, identify the line to be modified and set the IP address accordingly. Save the file and make sure to reapply the device configuration by using the "nmcli" command with the "device reapply" options.

  4. How to Change Your IP Address From the Command Line in Linux

    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. To change the settings, you also use the ifconfig command, this time with a few additional parameters.

  5. Linux change ip address

    Q. How do I change ip address in Linux? A. There are different ways to change IP address in Linux (a) Command Line tools (b) Modify configuration files (c) Use GUI tools Task: Display current IP address and setting for network interface called eth0 Use ifconfig command: # ifconfig eth0 Output: eth0 Link encap:Ethernet HWaddr […]

  6. How to Use the ip Command on Linux

    The ip command has replaced the older ifconfig command in modern versions of Linux. The ip command allows you to configure IP addresses, network interfaces, and routing rules on the fly without rebooting. Run "ip addr" in the Terminal to get your PC's local IP address. You can configure IP addresses, network interfaces, and routing rules on the ...

  7. How to Change IP Address in Linux [3 Effective Methods]

    To change IP address in Linux, you have options that suit your preferences. For advanced users and scripting, the ifconfig command provides command-line control. Network Manager offers a user-friendly graphical interface, while the ip command provides extensive network configuration capabilities. 1. Using the ifconfig Command. This method ...

  8. Change IP address on Ubuntu Server

    Our secondary or virtual IP address in this case is 192.168.1.204. To apply the new Netplan changes execute: $ sudo netplan apply. Alternatively, if you run into some issues run: $ sudo netplan --debug apply. Confirm that you now have a virtual IP address by using the ip a command: $ ip a.

  9. How to change ip address in ubuntu desktop through command line

    Add an IP address to my wireless interface (ip addr add) n2:~$ sudo ip a a 10...56/24 dev wlan0 [sudo] password for bensley: Show my IP addresses again, note the additional IP on wlan0 ( ip addr )

  10. Ubuntu Change IP

    How do I change IP address under Ubuntu Linux using GUI and command line options? A. ... Alternatively, open terminal (command line) and execute the following command: $ network-admin & When you start Network Administration Tool, you will be prompted for the administrator password, this is necessary because the changes done with this tool will ...

  11. Linux ip Command with Examples

    For example, to bring the interface eth0 online, you would type:. ip link set eth0 up. And to bring if offline. ip link set eth0 down Displaying and Altering the Routing Table #. To assign, remove, and display the kernel routing table use the route object. The most commonly used commands when working with the routes objects are: list, add, and del. Display routing table #

  12. How do I change the IP address/netmask and hostname on the command line

    Here are some example configuration files: /etc/hosts. 127.0.0.1 localhost.localdomain localhost 192.168..254 server1.example.com server1

  13. Linux ip Command Examples

    To get information about each object use help command as follows: $ ip OBJECT help $ ip OBJECT h $ ip a help $ ip r help Warning: The commands described below must be executed with care.If you make a mistake, you will lose connectivity to the server. You must take special care while working over the ssh based remote session.

  14. Manual Network Configuration in Linux and How to Set a Static IP Address

    In this tutorial, we look at standard low-level files and tools to configure our IP address settings. We start off by briefly discussing dynamic and static addresses. After picking static IP network configuration as an example, we look at a universal way to perform it under Linux. Next, we explore network managers in detail.

  15. How to change IP address on RHEL 8 / CentOS 8 Linux

    The GUI way. The easiest way to change your IP address in RHEL 8 / CentOS 8 is to use GNOME 's Settings window. Go to Settings and the last entry in the left side panel is Network. Click on Network and click the wheel button next to your network card. This will bring up another window with five tabs, one of which is IPv4.

  16. Set static IP in Ubuntu using Command Line

    Step 2: See current IP address. Now that you know which interface needs to be addressed, let us edit a file. Before I change my IP address/set a static one, let us first see what my current IP address is. $ hostname -I 192.168.122.69. Nice! But let's change it to '192.168.122.128' for demonstration purposes. Step 3: See the gateway

  17. Setup DHCP or static IP address from command line in Linux

    With DHCP, you get IP address, subnet mask, broadcast address, Gateway IP and DNS ip addresses. Go to step xxx to test your internet connection. Step 4.2 - Setup static IP, subnet mask, broadcast address in Linux. Use the following command to setup IP, subnet mask, broadcast address in Linux. Note that I've highlighted the IP addresses in ...

  18. How to Configure Static IP Address on Ubuntu 20.04

    Depending on the interface you want to modify, click either on the Network or Wi-Fi tab. To open the interface settings, click on the cog icon next to the interface name. In "IPV4" Method" tab, select "Manual" and enter your static IP address, Netmask and Gateway. Once done, click on the "Apply" button.

  19. Linux ifconfig Command

    With the ifconfig command, you can assign an IP address and netmask to a network interface. Use the following syntax to assign the IP address and netmask: ifconfig [interface-name] [ip-address] netmask [subnet-mask] For example, to assign the IP address 192.168..101 and netmask 255.255.. to the interface eth0, you would run:

  20. how can I change the interface ip address in linux without ifconfig

    You can also use ip route add or ip r a. First add your IP to the route table ip route add 192.168.10.100 dev ens160 proto static metric 100 Then add the route via the gateway ip route add default via 192.168.10.1 dev ens160 proto static metric 100 These changes will be temporary until a reboot. To make them persist, you will need to add the changes to your NIC.

  21. How can I change the IP and gateway addresses permanently?

    10. I recently installed Linux Ubuntu 14.04 to my computer. To enable internet connection I needed to change my IP and Gateway address. I did the following as a root user. # ifconfig eth0 "my ip address here" netmask 255.255.255. up. # route add default gw " gw address here". It works fine for a couple of minutes but then goes back to the ...

  22. How to configure a static IP address on CentOS 7 / RHEL 7

    Verify new IP settings using the ip command for the NIC named eth0: # ip a s eth0 Verify new routing settings: # ip r Next, verify DNS servers settings using the cat command or grep command to query the /etc/resolv.conf file as follows: # cat /etc/resolv.conf Finally verify the internet connectivity using the ping command: # ping -c 3 cyberciti ...

  23. How to Configure Static IP Address on Ubuntu 24.04 (Desktop)

    Configure Static IP Address on Ubuntu 24.04 Using GUI. Login to your desktop, click on the network icon and then choose Wired option as shown below: We will get the following window, click on "gearbox" icon. Go to IPv4 tab, there you will see that DHCP is enabled for automatic IP allocation. Choose Manual option to configure static IP ...

  24. How to Find the Subnet Mask of Your Computer?

    Step 2: Click on Network and Internet. Step 3: Click on Network and Sharing Center. Step 4: Click on the network connection you want to check (as shown below). Step 5: Click the Details button. Your subnet mask will be listed under the Network Connection Details ( as shown below). Method 3: Calculate a Subnet Mask from the IP Address.

  25. Change the hostname of your AL2 instance

    To change the system hostname without a public DNS name. For AL2: Use the hostnamectl command to set your hostname to reflect the desired system hostname (such as webserver ). [ec2-user ~]$ sudo hostnamectl set-hostname webserver.localdomain. For Amazon Linux AMI: On your instance, open the /etc/sysconfig/network configuration file in your ...