• PRO Courses Guides New Tech Help Pro Expert Videos About wikiHow Pro Upgrade Sign In
  • EDIT Edit this Article
  • EXPLORE Tech Help Pro About Us Random Article Quizzes Request a New Article Community Dashboard This Or That Game Popular Categories Arts and Entertainment Artwork Books Movies Computers and Electronics Computers Phone Skills Technology Hacks Health Men's Health Mental Health Women's Health Relationships Dating Love Relationship Issues Hobbies and Crafts Crafts Drawing Games Education & Communication Communication Skills Personal Development Studying Personal Care and Style Fashion Hair Care Personal Hygiene Youth Personal Care School Stuff Dating All Categories Arts and Entertainment Finance and Business Home and Garden Relationship Quizzes Cars & Other Vehicles Food and Entertaining Personal Care and Style Sports and Fitness Computers and Electronics Health Pets and Animals Travel Education & Communication Hobbies and Crafts Philosophy and Religion Work World Family Life Holidays and Traditions Relationships Youth
  • Browse Articles
  • Learn Something New
  • Quizzes Hot
  • This Or That Game New
  • Train Your Brain
  • Explore More
  • Support wikiHow
  • About wikiHow
  • Log in / Sign up
  • Computers and Electronics
  • Operating Systems

How to Assign an IP Address on a Linux Computer

Last Updated: July 28, 2022 Tested

Debian, Ubuntu, & Linux Mint

Red hat, centos, & fedora.

This article was co-authored by wikiHow staff writer, Jack Lloyd . Jack Lloyd is a Technology Writer and Editor for wikiHow. He has over two years of experience writing and editing technology-related articles. He is technology enthusiast and an English teacher. The wikiHow Tech Team also followed the article's instructions and verified that they work. This article has been viewed 725,243 times. Learn more...

This wikiHow teaches you how to assign a new IP address to your computer when using Linux. Doing so can prevent connection issues for the item in question.

Step 1 Verify your Linux version.

  • Press Ctrl + Alt + T or Ctrl + Alt + F1 (if you're on a Mac, substitute the ⌘ Command key for Ctrl .
  • Click the text box at the top or bottom of the screen if possible.
  • Open the Menu window and find the "Terminal" application, then click on it.

Step 3 Switch to root.

  • A "root" account is the Linux equivalent of an Administrator account on a Windows or Mac computer.

Step 4 Bring up a list of your current Internet items.

  • The top item should be your current router or Ethernet connection. This item's name is "eth0" (Ethernet) or "wifi0" (Wi-Fi) in Linux.

Step 5 Find the item to which you want to assign an IP address.

  • In most cases, this is the "eth0" or "wifi0" item.

Step 6 Change the item's IP address.

  • To assign an IP of "192.168.2.100" to your ethernet connection ("eth0"), for example, you'd enter sudo ifconfig eth0 192.168.0.100 netmask 255.255.255.0 here.

Step 7 Assign a default gateway.

  • If you have a different DNS server address that you would rather use, enter that in the place of 8.8.8.8 .

Step 9 Check your item's new IP address.

  • 5 Find the network connection that you want to change. This will normally be the Ethernet or Wi-Fi connection, which has an IP address currently listed on the right side of the window.

Step 6 Switch to the network scripts directory.

  • For a network named "eno12345678", for example, you'd enter vi ifcfg-eno12345678 here.

Step 9 Edit the network's information.

  • BOOTPROTO - Change dhcp to none
  • Any IPV6 entry - Delete any IPV6 entries entirely by moving the cursor to the I on the left and pressing Del .
  • ONBOOT - Change no to yes

Step 10 Enter a new IP category.

  • For example: to use "192.168.2.23" as your IP address, you'd type in IPADDR=192.168.2.23 and press ↵ Enter .
  • Type in PREFIX=24 and press ↵ Enter . You can also enter NETMASK=255.255.255.0 here.
  • Type in GATEWAY=192.168.2.1 and press ↵ Enter . Substitute your preferred gateway address if different.

Step 12 Save and exit the file.

Expert Q&A

  • Some very specific Linux distributions will require you to go through a different process to assign an IP address. To see your specific distribution's specifications, check online. Thanks Helpful 0 Not Helpful 0

ip address assign linux

  • Don't forget to switch back to the regular (non-root) user account when you're done. Thanks Helpful 1 Not Helpful 1

You Might Also Like

Set up a Network in Ubuntu

  • ↑ https://danielmiessler.com/study/set_ip/
  • ↑ https://www.youtube.com/watch?v=oQd5eG9BZXE&t=

About This Article

Jack Lloyd

  • Send fan mail to authors

Reader Success Stories

Buddy HaDagi

Buddy HaDagi

Jan 27, 2017

Is this article up to date?

ip address assign linux

Dmitry Ugay

Oct 10, 2017

Am I a Narcissist or an Empath Quiz

Featured Articles

Do the Worm

Trending Articles

How to Take the Perfect Thirst Trap

Watch Articles

Wrap a Round Gift

  • Terms of Use
  • Privacy Policy
  • Do Not Sell or Share My Info
  • Not Selling Info

wikiHow Tech Help Pro:

Level up your tech skills and stay ahead of the curve

Linux System Computers

Linux Assign IP Address: Step-by-Step Guide to Assigning an IP Address

Assigning an IP address to a network interface is a fundamental task in Linux system administration. Whether you are setting up a new network or troubleshooting connectivity issues, knowing how to assign an IP address is essential. In this step-by-step guide, we will walk you through the process of assigning an IP address in Linux, covering everything from opening a terminal window to verifying the IP address assignment. By the end of this article, you will have a clear understanding of how to assign an IP address in Linux and be able to confidently manage your network interfaces.

1. Open a terminal window

The first step in assigning an IP address in Linux is to open a terminal window. This can be done by clicking on the terminal icon in your desktop environment or by using the keyboard shortcut Ctrl+Alt+T. The terminal window provides a command-line interface where you can enter the necessary commands to assign an IP address.

2. Log in as the root user or use the sudo command to gain administrative privileges

In order to assign an IP address, you need administrative privileges. This can be achieved by either logging in as the root user or using the sudo command. If you are logged in as the root user, you can skip this step. Otherwise, you can use the sudo command before each command that requires administrative privileges. For example, to assign an IP address, you would use the command sudo ifconfig eth0 192.168.1.100.

3. Identify the network interface you want to assign the IP address to

Before assigning an IP address, you need to identify the network interface you want to assign it to. This can be done using the ifconfig or ip addr command. The ifconfig command displays information about all the network interfaces on your system, including their names and IP addresses. The ip addr command provides more detailed information about the network interfaces, including their names, IP addresses, and other configuration settings.

4. Disable the network interface

Before assigning an IP address, it is recommended to disable the network interface. This ensures that there are no conflicts or issues during the assignment process. You can disable a network interface using the ifconfig or ip link set command. For example, to disable the eth0 interface, you would use the command sudo ifconfig eth0 down or sudo ip link set eth0 down.

5. Assign the IP address to the network interface

Once the network interface is disabled, you can assign the IP address to it. This can be done using the ifconfig or ip addr add command. For example, to assign the IP address 192.168.1.100 to the eth0 interface, you would use the command sudo ifconfig eth0 192.168.1.100 or sudo ip addr add 192.168.1.100 dev eth0. Make sure to replace “eth0” with the name of your network interface.

6. Set the network mask

In addition to the IP address, you also need to set the network mask for the network interface. The network mask determines the range of IP addresses that are considered part of the same network. You can set the network mask using the ifconfig or ip addr add command. For example, to set the network mask to 255.255.255.0 for the eth0 interface, you would use the command sudo ifconfig eth0 netmask 255.255.255.0 or sudo ip addr add 192.168.1.100/24 dev eth0.

7. Set the default gateway

The default gateway is the IP address of the router or gateway that connects your network to other networks or the internet. Setting the default gateway allows your system to send network traffic to destinations outside of your local network. You can set the default gateway using the route add default gw command. For example, to set the default gateway to 192.168.1.1, you would use the command sudo route add default gw 192.168.1.1.

8. Set the DNS server addresses

DNS (Domain Name System) server addresses are used to resolve domain names to IP addresses. By setting the DNS server addresses, your system can translate domain names into IP addresses and access websites and other network resources. You can set the DNS server addresses using the resolv.conf file or the network manager tool. The resolv.conf file is located in the /etc directory and can be edited using a text editor. The network manager tool provides a graphical interface for managing network settings.

9. Enable the network interface

After assigning the IP address, network mask, default gateway, and DNS server addresses, you can enable the network interface. This allows the interface to start sending and receiving network traffic. You can enable a network interface using the ifconfig or ip link set command. For example, to enable the eth0 interface, you would use the command sudo ifconfig eth0 up or sudo ip link set eth0 up.

10. Verify the IP address assignment

Once the network interface is enabled, you can verify the IP address assignment using the ifconfig or ip addr command. This will display the IP address, network mask, and other configuration settings for the interface. Make sure that the assigned IP address matches the one you intended to assign.

11. Test the network connectivity

After assigning the IP address, it is important to test the network connectivity to ensure that the assigned IP address is functioning correctly. You can test the network connectivity using the ping command. For example, to ping a remote server with the IP address 8.8.8.8, you would use the command ping 8.8.8.8. If the ping is successful, it means that your system is able to communicate with the remote server.

12. Save the changes to make them persistent across reboots

By default, the IP address assignment is temporary and will be lost when you reboot your system. If you want to make the IP address assignment persistent across reboots, you need to save the changes. The method for doing this may vary depending on the Linux distribution you are using. In most cases, you can edit the network configuration files in the /etc/network directory or use the network manager tool to save the changes.

In conclusion, assigning an IP address in Linux is a straightforward process that involves opening a terminal window, identifying the network interface, disabling the interface, assigning the IP address and network mask, setting the default gateway and DNS server addresses, enabling the interface, verifying the IP address assignment, testing the network connectivity, and saving the changes to make them persistent. By following this step-by-step guide, you can easily assign an IP address in Linux and manage your network interfaces effectively.

Frequently Asked Questions

1. can i assign multiple ip addresses to a single network interface.

Yes, you can assign multiple IP addresses to a single network interface in Linux. This can be useful in scenarios where you need to host multiple websites or services on a single server. To assign multiple IP addresses, you can use the ifconfig or ip addr add command multiple times, specifying a different IP address each time.

2. How do I assign an IP address using DHCP?

If you want to assign an IP address using DHCP (Dynamic Host Configuration Protocol), you can use the dhclient command. The dhclient command sends a DHCP request to the DHCP server on your network and obtains an IP address dynamically. To assign an IP address using DHCP, you can use the command sudo dhclient eth0, replacing “eth0” with the name of your network interface.

3. What should I do if I cannot connect to the network after assigning an IP address?

If you cannot connect to the network after assigning an IP address, there are a few troubleshooting steps you can try. First, make sure that the assigned IP address is within the correct range for your network. Check the network mask and default gateway settings to ensure they are correct. You can also try restarting the network interface or rebooting your system. If the issue persists, it may be a configuration issue or a problem with your network hardware.

Similar Posts

Best virtual machine options for running linux on windows: virtual machine with linux on windows.

Discover the best virtual machine options like Oracle VM VirtualBox and VMware Workstation to run Linux on Windows. Start virtualizing today and find the perfect solution for your needs.

Which is the Best Linux Distribution? Top Choices Revealed – Decide Wisely!

Discover the top Linux distributions and choose wisely! Explore Ubuntu, Fedora, Debian, and more. Find out which is the best Linux for you.

SSL Certificate Creation in Linux: Step-by-Step Guide for Secure Website Setup

Secure your website with SSL certificates in Linux. Install OpenSSL, generate private keys, create a CSR, and configure your web server. Follow our step-by-step guide for a secure website setup.

Linux ISO Creation: Step-by-Step Guide for Creating a Linux ISO | Get Started Now!

Discover the complete process of Linux ISO creation in our step-by-step guide. Choose a distribution, download the ISO, create a bootable drive, install Linux, and customize settings. Start creating your own Linux ISO today!

Top Mobile Device Linux Distributions: Find Your Perfect Fit Today!

Discover the freedom of open-source software on your mobile device with top mobile device Linux distributions like Ubuntu Touch, Sailfish OS, and Tizen. Unleash the power of Linux and find your perfect fit today.

Linux Daemon Reload: Quick Command to Reload a Linux Daemon

Learn how to quickly reload a Linux daemon with common commands like systemctl reload, service reload, and more. Improve your server performance now!

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.

 Powerful Protection for WordPress, from Shield Security

GoLinuxCloud

16 Linux ip command examples to configure network interfaces (cheatsheet)

The ip is a very powerful utility that is used to perform many tasks. Multiple older utilities such as ifconfig and route command were earlier used to perform these functions. In this article I will share different examples to configure network interfaces and routes using ip command .

Install iproute rpm

By default iproute rpm is installed on all variants of RHEL/CentOS Linux , you can also find ip binary command in the rescue and emergency target.

The absolute path is /usr/sbin/ip

1. Show IP Address of all the available interfaces using ip command

Use ip addr show to show the IP Address of all the available network interfaces on your Linux system

Here I have three interfaces (including the loopback interface), wherein we can check the IP Address of individual interface as highlighted above.

2. Show IP Address of individual interface

You can use " dev " argument along with " ip addr show " to display information of provided interface only. Here we are displaying IP Address detail for enp0s9 interface only.

3. List interfaces based on interface type

There are various types of NIC which can be available on your Linux system such as vlan , bond, bridge, vxlan etc.

Now to list only bridge interfaces on your system:

To list bond interface from your system

4. Check if NIC's link state is enabled or disabled

" ip link " will manage and display the state of all network interfaces. To display the current state of all the interfaces

To check the link state of individual interface

5. Change NIC's Link state

Since our NIC interface is already in enabled state, let us turn down link state for enp0s9 interface

Check the link state again for enp0s9

Now since it is in DOWN state, let us change the link status for enp0s9 to UP

6. Assign/Add IPv4 and IPv6 address

To assign ipv4 address using you can use " ip addr add ". To demo this step I have already temporarily unassigned/removed IP address from enp0s9 interface.

To assign IPv4 address using ip command you would need netmask prefix value which here for me is "24". You can either calculate this prefix value or you can use other online network calculators which can help you get the prefix value depending upon your netmask.

To check the assigned IPv4 Address for enp0s9 interface

To assign IPv6 address using ip command you can use the same command as used for IPv4 address but with the IPv6 address and netmask

Verify the IPv6 address assigned to the provided interface

7. Un-Assign/Delete IPv4 and IPv6 address

You can un-assign or delete an assigned ip address from an interface using " ip addr del " argument. Here you must give the exact IP address along with the prefix value to un-assign the ip address.

Check and verify if the ip address was un-assigned sucessfully from the provided interface

You can un-assign or delete the IPv6 address for individual interface using the same command as used for IPv4 address above.

Next check the IPv6 Address of the interface to make sure it is un-assigned from the provided interface

8. Un-assign/delete all protocol addresses from individual interface

By using " ip addr del " we only remove the provided address assigned to the respective interface. But if you wish to remove all the protocol address assigned to individual interface then you must use flush

Next check the interface detail

As you see both IPv4 and IPv6 addresses are removed.

9. Display detailed statistics of interface

To get more detailed information on packet statistics for individual interface using " -s " argument

If the "-s" option appears twice or more, the amount of information increases.

10. List available routes

To list all the available routes on your Linux system

You can also use " ip route " or " ip route show " to get the list of available routes in the routing table

11. Add default route to routing table

To add default route (adding an entry in the routing table) use " ip route add default "

Verify the available default routes in the routing table

To add more details for the default route as we have for other routes

Verify the default route again using ip command

12. Delete default route from routing table

To delete the default route, instead of using " add ", use " delete ". Now here I have two default routes, where I wish to delete the route with 10.0.2.2 for enp0s3 interface

Delete the default route

Verify the available routes in the routing table

You can also remove the default route using interface name to delete all the default routes mapped to provided interface

13. Add additional route to the routing table

Now after adding default route, you can also add additional routes to the routing table. Here we will add a route to 192.168.168.0/24 via the route 192.168.0.1

14. Delete additional route from routing table

Here we had added a new route for 192.168.168.0/24 via 192.168.0.1 . so we will attempt to delete the same here

Verify the route list again

15. Replace existing routes from routing table

We can also replace certain directives from existing routes in the routing table. In our last example we added route 192.168.168.0/24 via 192.168.0.1 so we will change this to 192.168.168.0/24 via 10.0.2.2 gateway via a different interface (enp0s3)

My existing list of routes

Replace the route values

Verify the new route list

16. Display the route an address will take

Now we have added all the routes, but we would like to know the route which any address on the linux system will take

To know the route which will be used by 192.168.168.10 address

To know the route which will be used by 192.168.0.10 address

Linux ip command is a very handy tool for Linux Administrators. The only drawback with this tool is that the changes are non-persistent which means this will not survive a reboot. But in many cases such as in rescue mode or to verify temporary network changes we can use this tool to create and assign network to interfaces.

Lastly I hope this article with different ip command examples to perform network related activities (cheatsheet) on Linux was helpful. So, let me know your suggestions and feedback using the comment section.

I have used below external references for this tutorial guide man page for ip command

Deepak Prasad

He is the founder of GoLinuxCloud and brings over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels in various domains, from development to DevOps, Networking, and Security, ensuring robust and efficient solutions for diverse projects. You can reach out to him on his LinkedIn profile or join on Facebook page.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to [email protected]

Thank You for your support!!

Leave a Comment Cancel reply

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

Notify me via e-mail if anyone answers my comment.

Tecmint: Linux Howtos, Tutorials & Guides

How to Set Static IP Address and Configure Network in Linux

If you are a Linux system administrator, time will come when you will need to configure networking on your system. Unlike desktop machines where you can use dynamic IP addresses, on a server infrastructure, you will need to setup a static IP address (at least in most cases).

Read Also: How to Set or Change System Hostname in Linux </p

This article is meant to show you how to configure static IP address on most frequently used Linux distributions.

For the purpose of this tutorial, we will use the following Internet Protocol version 4 (IPv4) details:

Configure Static IP Address in RHEL/CentOS/Fedora:

To configure static IP address in  RHEL / CentOS / Fedora , you will need to edit:

Where in the above "ifcfg-eth0" answers to your network interface eth0 . If your interface is named “ eth1" then the file that you will need to edit is "ifcfg-eth1" .

Let’s start with the first file:

Open that file and set:

Note : Make sure to open the file corresponding to your network interface. You can find your network interface name with ifconfig -a command .

In that file make the following changes:

You will only need to edit the settings for:

  • DNS1 and DNS2

Other settings should have already been predefined.

Next edit resolve.conf file by opening it with a text editor such as nano or vi :

Once you have made your changes restart the networking with:

Set Static IP Address in Debian / Ubuntu

To setup static IP address in Debian / Ubuntu , open the following file:

You may see a line looking like this:

Change it so it looks like this:

Save the file and then edit /etc/resolv.conf like this:

Restart the networking on your system with:

Your static IP address has been configured.

Conclusion:

You now know how to configure a static IP address on a Linux distro. If you have any questions or comments, please do not hesitate to submit them in the comment section below.

Previous article:

Next article:

Photo of author

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Related Posts

Extract Linux Tar Files Different or New Directory

How to Extract Tar Files to Specific or Different Directory in Linux

Debian Goodies Utilities to Manage Debian Packakges

8 Useful ‘Debian Goodies Utilities’ for Package Management

Delete User Accounts with Home Directory in Linux

How to Delete User Accounts and Their Home Directories in Linux

Find and Kill Running Processes in Linux

How to Find and Kill Running Processes in Linux

Set System Time, Date and Timezone in Linux

How to Set Time, Timezone and Synchronize System Clock in Linux

FFMPEG Command Examples in Linux

15 Must-Know FFmpeg Commands for Video, Audio & Image Conversion

32 thoughts on “How to Set Static IP Address and Configure Network in Linux”

The time will come when you will need to configure networking on your system. Unlike desktop machines where you can use dynamic IP addresses, on a server infrastructure, you will need to set up a static IP address (at least in most cases).

Terrible – and my ‘ linux distro ‘ isn’t the same as yours, there’s no ‘ /etc/sysconfig/ ‘ folder.

In Ubuntu 20.04 there is no interfaces file they switch to netplan . If you can update this article to include the new change it will help a lot.

thanks Raouf

Well, this isn’t correct. Just trashed my Linux mint distro

Is it public Static IP? or can I use to access data from other networks?

Failed to restart network.service: Unit network.service not found.

I’m asking a question on a fairly old thread, but just in case, is it possible to do this on a WIFI network?

For example, when using the first command (# nano /etc/network/interfaces ) in Ubuntu, the result I see is:

There isn’t an “ eth0 ” on my server because it is connected by WIFI only. Will it still work using another option?

Yes it will work I think so, just change the settings in the interfaces file as explained in this article.

I set the static IP in ifcfg-eth0, added HWADDR and UUID, but on reboot system does not associate the IP to eth0.

This is VM. Any idea why its happening and steps to troubleshoot.

I think you need to make sure that you select “ manual ” and the correct IP address, subnet mask, and gateway and save the configuration as explained in the article. Also, I personally would select a new and different IP address, so that you can really check if it has been saved by opening the terminal and typing:

after a restart.

If i set ip address as static am not able to ping google.com why and also packages are not installed.

Please give me reply as soon as possible.

@Rajeshkar,

Please add the DNS Name servers in your /etc/resolv.conf file..

@Ravi Saive thanks for your reply , yes i did /etc.resolv.conf also but getting the same problem

@Rajesekar,

The file is /etc/resolv.conf , in this file add your DNS name servers for example.

When I enter the /etc/resolv.conf file, what is it supposed to look like? And when you say “edit” do you mean delete what’s there and write what you’ve provided, or just add new lines?

Hello Marin, Thank you very much for this article. It was a major help in my class project. This is my first time using a vm and it is an awesome learning experience. I’m really glad I ran into this article, it was well written and easy to follow.

Just wanted to say a million thank you’s for this well-written, comprehensive and easily-understood article! Awesome stuff! A real lifesaver too, as I had to quickly configure a static IP for myself to get access to remote computing. Thank you! :-D

A question from a linux newbie. Does this instruction apply for both ubuntu running on my desktop PC as well as debian linux on an embedded board?

Yes, the instructions will works on any Debian/Ubuntu based distribution without any issues..have you tried on your embedded board? does these instructions worked? let us know.

Hi Ravi, thanks for your reply.

Default the folder /etc/sysconfig does not exist on my embedded system. Of Course i could create it as well as the files mentioned, but it would be out of the context of this instructions.

Thanks, Rob

I found here very good stuff! You are doing an excellent job and I like your site! Thanks!

Thanks for finding this site very useful and thanks for appreciating our work, Keep visiting for more such useful articles…

Great job, I was I actually looking for an article like this one. So thank you so very much. Keep up the good work.

Thanks for appreciating and finding this article useful, keep connected to Tecmint for such wonderful articles…:)

What if I have 2 NICs on my server one for LAN & one for WAN and I want to set one of them (WAN) as default gateway? How to configure this server as gateway and as a router.

The easiest way to add default gateway using route command as shown:

Don’t forget to replace the gateway IP address and interface-name in the above command.

One can also use following command to setup static IP on eth0 interface for example. # ifconfig eth0 192.168.1.1 netmask 255.255.255.0 up # route add default gw 192.168.0.1 # service network restart

Thanks for the tip, but I think setting IP address directly from the commandline using ifconfig and route will only allow you to set temporarily, once you reboot, these settings disappears. So, the best option to set static IP address permanently in network configuration files only….

wipe on reboot, so that best option is to set permannetly

Hello Ravi, What is difference between the service “NetworkManager” and “network”

@Augustine,

This article will help you to understand the difference between and NetworkManager and Network: http://askubuntu.com/questions/1786/what-is-the-difference-between-network-manager-and-ifconfig-ifup-etc

Why do we need to specify DNS in both ifcfg-eth0 and resolvlf.conf?

Hello Augustine,

Actually if you have added the DNS servers in the ifcfig-eth0 file the DNS servers will be automatically added to /etc/resolv.conf. You can skip defining the DNS servers in the ifcfig-eth0 file, but then you will need to have them set in /etc/resolv.conf manually. It’s a good practice to make sure that the DNS servers are specified correctly in both files, this is why the article says to set them in both files.

Got something to say? Join the discussion. Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

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

How-To Geek

How to set a static ip address in ubuntu.

When static is the way forward.

Quick Links

What is a static ip address, setting a static ip in ubuntu, set a static ip in ubuntu with the gui, connection convenience, key takeaways.

After gathering your connection name, subnet mask, and default gateway, you can set a static IP address in the terminal using the nmcli command. Or, in the GNOME desktop, open your connection settings and click the + icon, then enter the info for your static IP address there.

Your home network relies on IP addresses to route data between devices, and sometimes on reconnecting to the network a device's address can change. Here's how to give an Ubuntu Linux computer a permanent IP address that survives reboots.

Everything on your network home network, whether it's using a wired connection or Wi-Fi, has an IP address . IP stands for Internet Protocol. An IP address is a sequence of four numbers separated by three dots. Each IP address that is unique within that network.

IP addresses act as numeric labels. Your router uses these labels to send data between the correct devices. Usually, your router assigns IP addresses. It knows which IP addresses are in use and which are free. When a new device connects to the network, it requests an IP address and the router allocates one of the unused IP addresses. This is called DHCP, or dynamic host configuration protocol .

When a device is restarted or powered off and on, it may receive its old IP address once more, or it might be allocated a new IP address. This is normal for DHCP and it doesn't affect the normal running of your network. But if you have a server or some other computer that you need to be able to reach by its IP address, you'll run into problems if its IP address doesn't survive power downs or reboots.

Pinning a specific IP address to a computer is called allocating a static IP address . A static IP address, as its name suggests, isn't dynamic and it doesn't change even if the computer is power-cycled .

Nmcli is the command-line network manager tool , and can be used to change your IP address, configure network devices, and --- relevant to our purposes --- set up a static IP in Ubuntu.

We're demonstrating this technique on Ubuntu 22.04 LTS, but it ought to work on any Linux distribution, including Ubuntu 23.04. The nmcli tool was released in 2004, so it should be present on just about any standard distribution.

Let's take a look at the network connections that already exist on the computer. We're using the connection command with the show argument.

nmcli connection show

Using nmcli to list network connections

This displays some information about each connection. We only have a single connection configured.

The details of a single network connection displayed by nmcli

The output is wider than the terminal window. This is the information that we're shown.

  • Name : Our network connection is called "netplan-enp0s3."
  • UUID : The universally unique identifier Linux uses to reference this connection internally.
  • Type : This is an ethernet connection.
  • Device : This connection is using the "enp0s3" network interface. It's the only network card in this computer.

We can use the ip command to discover the IP address this computer is using.

The output of the ip addr command showing the ip address of the computer

In the output we can see the "enp0s3" entry, and its current IP address, 192.168.86.117. The "/24" is a shorthand way of saying that this network uses a 255.255.255.0 subnet mask . Take a note of this number, we'll need to use it later.

We need to choose the IP address we're going to set as our static IP address. Obviously, you can't use an IP address that is already in use by another device. One safe way to proceed is to use the current IP address assigned to the Ubuntu system. We know for certain that nothing else is using that IP address.

If we want to use a different IP address, try pinging it. We're going to test whether IP address 192.168.86.128 is in use. If everything else on your network uses DHCP and you get no response to the ping command, it should be safe to use.

ping 192.168.86.128

Using ping to determine if an IP address is in use

Even if another device had previously used that IP address, it'll be given a new IP address when it next boots up. Nothing responds to the ping requests, so we're clear to go ahead and configure 192.168.86.128 as our new static IP.

We also need to know the IP address of your default gateway , which will usually be your broadband router. We can find this using the ip command and the route option, which we can abbreviate to "r."

Using the ip command to find the IP address of the default gateway

The entry that starts with "default" is the route to the default gateway. Its IP address is 192.168.86.1. Now we can start to issue commands to set up our static IP address.

The first command is a long one.

sudo nmcli con add con-name "static-ip" ifname enp0s3 type ethernet ip4 192.168.86.128/24 gw4 192.168.86.1

Creating a new connection with the nmcli command

Taken in small chunks, it's not as bad as it looks. We're using sudo . The nmcli arguments are:

  • con : Short for "connection."
  • add : We're going to add a connection.
  • con-name "static-ip" : The name of our new connection will be "static-ip."
  • ifname enp0s3 : The connection will use network interface "enp0s3."
  • type ethernet : We're creating an ethernet connection.
  • ip4 192.168.86.128/24 : The IP address and subnet mask in classless inter-domain routing notation . This is where you need to use the number you took note of earlier.
  • gw4 192.168.86.1 : The IP address of the gateway we want this connection to use.

To make our connection a functioning connection, we need to provide a few more details. Our connection exists now, so we're not adding anything, we're modifying settings, so we use the mod argument. The setting we're changing is the IPv4 DNS settings. 8.8.8.8 is the IP address of Google's primary public DNS server , and 8.8.4.4 is Google's fallback DNS server.

Note that there is a "v" in "ipv4." In the previous command the syntax was "ip4" without a "v." The "v" needs to be used when you're modifying settings, but not when adding connections.

nmcli con mod "static-ip" ipv4.dns "8.8.8.8,8.8.4.4"

Using the nmcli command to set the DNS servers for a connection

To make our IP address static, we need to change the method which the IP address obtains its value. The default is "auto" which is the setting for DHCP. We need to set it to "manual."

nmcli con mod "static-ip" ipv4.method manual

Using the nmcli command to set an IP address to static

And now we can start or "bring up" our new connection.

nmcli con up "static-ip" ifname enp0s3

Using the nmcli command to start a network connection

We didn't get any error messages which is great. Lets use nmcli to look at our connections once more.

nmcli con show

The details of two network connections displayed by nmcli

Here's the output:

Our static-ip connection is active and using device "enp0s3." The existing connection "netplan-enp0s3" is no longer associated with a physical network interface because we've pinched "enp0s3" from it.

Click the icons at the far-right end of the system bar to show the system menu, then click on the "Wired Connected" menu option. If you're using a wireless connection, instead click the name of your Wi-Fi network.

The available connections are displayed. A dot indicates which is in use. Click the "Wired Settings" or "Wi-Fi Settings" menu option. The details of the active connection are displayed.

If you followed our previous instructions the new connection will be the active connection. We can see our new "static-ip" connection has the IP address, default gateway, and DNS servers that we set for it.

The system menu with the

To create a new connection using the "Settings" application, click the " + " icon on the "Networks" page, above the list of wired connections.

The wired connection section in the Network tab of the Settings app

A dialog appears. We need to provide a name for our new static IP connection.

Giving a name to a new connection profile in the

We're calling our new connection "static-2." Click the "IPv4" tab.

Supplying the IPv4 connection details to a new connection profile in the

Select the "Manual" radio button, and complete the "Address", "Netmask", and "Gateway" fields. Also complete the DNS field, and then click the green "Apply" button. Note the comma between the DNS entries.

Our new connection is listed in the "Wired" connections pane.

A newly-added connection in the wired connection section of the Network tab of the Settings app

You can swap between the available connections by clicking directly on their names.

If you want to modify a connection after you create it, click the cog icon. In this case, we'll enter the settings for the "static-ip" connection.

The wired connection section in the Network tab of the Settings app

A dialog box opens. Click on the "IPv4" tab.

The IPv4 tab of the connection settings dialog

Because we set our new IP address to be static, the "Manual" radio button is selected. You could change this back to DHCP by selecting the "Automatic (DHCP)" radio button, and clicking the green "Apply" button.

Using the nmcli command or the GNOME desktop and apps, you can hop between network connections very easily and very quickly.

It's more convenient to have a selection of connection profiles and move between them as you need to, rather than to have one that you keep editing. If something goes horribly wrong with the connection you're editing or adding, you can always fall back on one of the existing connections.

It's FOSS

How to Assign Static IP Address on Ubuntu Linux

Dimitrios

Brief: In this tutorial, you’ll learn how to assign static IP address on Ubuntu and other Linux distributions. Both command line and GUI methods have been discussed.

IP addresses on Linux Systems in most cases are assigned by Dynamic Host Configuration Protocol (DHCP) servers. IP addresses assigned this way are dynamic which means that the IP address might change when you restart your Ubuntu system . It’s not necessary but it may happen.

Dynamic IP is not an issue for normal desktop Linux users in most cases . It could become an issue if you have employed some special kind of networking between your computers.

For example, you can share your keyboard and mouse between Ubuntu and Raspberry Pi . The configuration uses IP addresses of both system. If the IP address changes dynamically, then your setup won’t work.

Another use case is with servers or remotely administered desktops. It is easier to set static addresses on those systems for connection stability and consistency between the users and applications.

In this tutorial, I’ll show you how to set up static IP address on Ubuntu based Linux distributions. Let me show you the command line way first and then I’ll show the graphical way of doing it on desktop.

Method 1: Assign static IP in Ubuntu using command line

Static IP set up Ubuntu

Note for desktop users : Use static IP only when you need it. Automatic IP saves you a lot of headache in handling network configuration.

Step 1: Get the name of network interface and the default gateway

The first thing you need to know is the name of the network interface for which you have to set up the static IP.

You can either use ip command or the network manager CLI like this:

In my case, it shows my Ethernet (wired) network is called enp0s25:

Next, you should note the default gateway IP using the Linux command ip route :

As you can guess, the default gateway is 192.168.31.1 for me.

Step 2: Locate Netplan configuration

Ubuntu 18.04 LTS and later versions use Netplan for managing the network configuration. Netplan configuration are driven by .yaml files located in /etc/netplan directory.

By default, you should see a .yaml file named something like 01-network-manager-all.yaml, 50-cloud-init.yaml, 01-netcfg.yaml.

Whatever maybe the name, its content should look like this:

You need to edit this file for using static IP.

Step 3: Edit Netplan configuration for assigning static IP

Just for the sake of it, make a backup of your yaml file.

Please make sure to use the correct yaml file name in the commands from here onward.

Use nano editor with sudo to open the yaml file like this:

Please note that yaml files use spaces for indentation . If you use tab or incorrect indention, your changes won’t be saved.

You should edit the file and make it look like this by providing the actual details of your IP address, gateway, interface name etc.

In the above file, I have set the static IP to 192.168.31.16.

Save the file and apply the changes with this command:

You can verify it by displaying your ip address in the terminal with ‘ip a’ command.

If you don’t want to use the static IP address anymore, you can revert easily.

If you have backed up the original yaml file, you can delete the new one and use the backup one.

Otherwise, you can change the yaml file again and make it look like this:

Method 2: Switch to static IP address in Ubuntu graphically

If you are on desktop, using the graphical method is easier and faster.

Go to the settings and look for network settings. Click the gear symbol adjacent to your network connection.

Assign Static IP address in Ubuntu Linux

Next, you should go to the IPv4 tab. Under the IPv4 Method section, click on Manual.

In the Addresses section, enter the IP static IP address you want, netmask is usually 24 and you already know your gateway IP with the ip route command.

You may also change the DNS server if you want. You can keep Routes section to Automatic.

Assigning static IP in Ubuntu Linux

Once everything is done, click on Apply button. See, how easy it is to set a static IP address graphically.

If you haven’t read my previous article on how to change MAC Address , you may want to read in conjunction with this one.

More networking related articles will be rolling out, let me know your thoughts at the comments below and stay connected to our social media.

Dimitrios is an MSc Mechanical Engineer but a Linux enthusiast in heart. His machines are powered by Arch Linux but curiosity drives him to constantly test other distros. Challenge is part of his per

Meet DebianDog - Puppy sized Debian Linux

Reduce computer eye strain with this nifty tool in linux, install open source dj software mixxx version 2.0 in ubuntu, install adobe lightroom alternative rawtherapee in ubuntu linux, complete guide to installing linux on chromebook, become a better linux user.

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

It's FOSS

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Your link has expired.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.

LinuxOPsys

Set IP Address in Linux Using ip Command

ip address assign linux

1. Introduction

The ip command is the most recommended command for network interface configuration in Linux. This is because of its extended feature set and by default all modern Linux Distributions include and maintain it.

In this guide, we learn how to set IP address in Linux using ip command.

2. Identifying Your Network Interface

Before setting the ip address it's good to know an overview of your available network interfaces. You can use ip link show command to display all the network interfaces along with their state and details.

ip address assign linux

The interfaces which I have are lo, enp0s3, enp0s8 and enp0s9. The first interface is lo stands for loopback - which used for local communication within the machine. The naming convention of the network interface depends on the system's distribution, version, and specific configurations.

From the output commonly we look for the number of interfaces, interface name, status, hardware address (MAC), and MTU size.

Remember ip link show command won't show ip address on the interfaces.

3. Set Temporary IP Address Using ip command

Before setting a temporary IP address you can verify the current network settings on all network interfaces. Use ip addr show command which includes all information network interface including its assigned IP addresses.

ip address assign linux

Except for enp0s8 interface, all other interfaces have IP addresses assigned.

You can use the following command to know the interface settings on a specific interface:

Let's add a new temporary IP address on the network interface, for this we use ip addr add command.

Here's an example of how you might add the IP address 192.168.56.102 with a subnet mask of 255.255.255.0 (or /24 in CIDR notation) to the interface enp0s8:

ip address assign linux

This command doesn't give any output. You can verify the IP address using ip addr show command.

This works on the fly and the network interface should be available to ping. That means no need to restart the network service. But this IP address is temporary means that it will be lost on reboot.

Note that this command requires root privileges, so you might need to use sudo.

4. Removing or Changing the Temporary IP Address

If you try to add another IP address to the same interface, it simply adds to the same interface.

For example, I am going to add 192.168.56.103/24 to the same interface enp0s8:

ip address assign linux

This command adds the new IP address 192.168.56.103/24 to enp0s8. Including the previous IP, you have a total of 2 IP addresses on the same interface.

To change the IP address using ip command , first you need to remove the current IP address and then add the new IP address. To remove the IP address use the ip addr del command and the syntax is similar to ip addr add command.

Here I have removed both IP addresses which were added earlier to the enp0s8 network interface.

Now you can add the new IP address to enp0s8 using ip addr add command:

5. Making the IP Address Change Permanent

So far every change we performed using ip command won't persist after the reboot.

You need to make changes to the network configuration file in the appropriate file to make the IP address permanent. Depending on the Linux Distribution this config file, type, and location varies.

Debian-based distributions (like Ubuntu):

The latest version of Ubuntu uses Netplan as the default network management tool. The config files are located under /etc/netplan directory. The config files are written in YAML. Note: You need to be careful about the spaces and indentation.

For the configuration, you can use the default file in /etc/netplan (looks like 01-netcfg.yaml, 01-network-manager-all.yaml) or create a new file starting with 01 and ending with .yaml.

You can add the following lines and configure your appropriate network settings.

Once the config file is updated, you can make the changes live using:

Red Hat-based distributions (like CentOS Stream, Fedora, RHEL) :

In Red Hat-based distributions the network configuration files are stored in /etc/sysconfig/network-scripts/ directory. The files are generally named ifcfg-[INTERFACE_NAME] and contain key-value pairs that define the network configuration.

Once the config file is edited you would need to restart the network service to make the changes effective.

If this resource helped you, let us know your care by a Thanks Tweet. Tweet a thanks

Like

Sorry about that.

About The Author

Bobbin zachariah.

Bobbin Zachariah

Bobbin Zachariah is an experienced Linux engineer who has been supporting infrastructure for many companies. He specializes in Shell scripting, AWS Cloud, JavaScript, and Nodejs. He has qualified Master's degree in computer science. He holds Red Hat Certified Engineer (RHCE) certification.

Nmap to Scan Open Ports – Examples + Screenshots

How to List Network Interfaces in Linux

How to Get IP address in Linux

How to Permanently add Static Route in Linux

Ping IPv6 Address from Windows and Linux CLI

How to Check Ports in Use in Linux (Listening Ports)

Tshark Examples with Cheat Sheet

2 thoughts on “Set IP Address in Linux Using ip Command”

Hi, thanks a lot for this article. I just saw a little mistake under 4: It must be sudo ip addr del 192.168.56.102/24 dev enp0s8

, so, not add but del.

Again, thanks a lot!

Thanks Sascha for pointing it out. I have fixed that typo.

Leave a Comment Cancel reply

How to configure IP address in Linux

An IP address is the software address of the computer. Two computers can communicate only if they have IP addresses. There are two ways to configure an IP address on Linux: temporary and permanent. A temporary IP address works only in the current login session. Linux stores it in the RAM and removes it when you log out from the current session. A permanent IP address works until a service or you manually update or change it. Linux stores it in a configuration file.

Setting a temporary IP address

To set a temporary IP address, we use the 'ip addr' command. This command adds the new IP address to the specified interface. It does not remove or update the existing IP address. It appends the current IP configuration.

Without any argument, it displays the IP configurations of all network devices.

To view the IP configuration of a particular device, specify the name of the interface as an argument after the show option. The following command displays the IP configuration of the ens160 interface.

To use this command to add a temporary IP address, we need to use the 'add' and 'dev' options with the command.

Specify the IP address with the subnet mask after the add option and the name of the interface after the dev option.

The following command adds the IP address 192.168.1.10/24 to the ens160 interface.

To verify the new IP address, you can check the IP configuration of the device again.

The following image shows the above exercise.

ip addr command

To learn more about the 'ip addr' command, you can check the following tutorial.

Linux ip address Command Usages and Examples

Setting a permanent IP address

There are four methods to configure a permanent IP address. These methods are: -

  • Changing the configuration file
  • Using the nmcli command
  • Using the nmtui utility
  • Using the nn-connection-editor tool

Let's discuss each method in detail.

Changing IP addresses in configuration files

Linux uses a configuration file for each interface to store its configuration. It stores all configuration files in /etc/sysconfig/network-scripts directory. For the naming convention of interface configuration files, it uses the 'ifcfg' prefix. After this prefix, it uses the name of the network card. For example, if the interface's name is ens160 , it will store its configuration in the ifcfg- ens160 file.

network configuration file

To configure a new IP address or change existing IP addresses, we use the IPADDR directive in this file. You can use any text editor to edit or update this file.

The following image shows how to change the existing IP address by editing the configuration file.

changing configuration files

Linux reads this file only when the interface starts. It does not actively monitor this file. If you change this file, you need to restart the interface to force Linux to reread the configuration file.

To force Linux to reread this file, you can use the ifdown and ifup commands. Specify the interface name as the argument with these commands.

restart interface to update the ip address

Using the nmcli command to configure IP addresses

If you do not want to edit the configuration file directly, you can use NetworkManager's tools. NetworkManager is the default network management service on Linux. It provides three tools for network configuration management. These tools are nmcli, nmtui, and nm-connection-editor.

NetworkManager uses the term 'connection' to refer to a network configuration file. It allows us to create multiple connections (configuration files) for the same interface. Multiple connections allow us to connect different networks without changing the IP configuration. For example, if you use your laptop at home and office, you can create two connections for your wireless interface: one for the home and another for the office. NetworkManager will automatically select the connection based on your location. If you use the laptop at the home, it will use the home connection, or if you use the laptop at the office, it will use the office connection.

To learn more about the NetworkManager, you can check the following tutorial.

Understanding Linux Network Manager Fundamental

Use the following command to list all connections (configuration files) of the interface.

The modify option allows us to modify all parameters of the connection. We can use this option to update the IP address. The following command sets the IP address to 192.168.1.100/24 .

After updating the IP address, use the following commands to restart the connection.

Now, check the IP address again.

using nmcli command to configure ip address

To learn more about the nmcli command, you check the following tutorial.

The nmcli command on Linux Examples and Usages

Using the nmtui utility to update IP addresses

The nmtui is a curses-based utility. It allows us to manage interfaces. The following command starts it.

nmtui command

Select the "Edit a connection" option and press the Enter key.

edit a connection

Select the NIC from the left pane, select the Edit option from the right pane, and press the Enter key.

select nic

Select the Automatic option from the IPv4 configuration option and press the Enter key.

automatic ip dhcp option

To obtain IP configuration from the DHCP Server, select the Automatic option. To set the IP configuration manually, use the Manual option.

dhcp option

Select the Show option and press the Enter key. Use the Tab key to switch between options.

show option

Set the IP address/subnet mask, Gateway IP address, and DNS Server IP address.

set ip adddress

Select the OK option and press the Enter key to accept the change.

confirm change

Select the Quit option and press the Enter key.

quit nmtui

When we exit the nmtui utility, it automatically applies the changes and updates the associated network configuration files. In the above example, since we assigned IP configuration to the eno16777736 interface, the nmtui utility updates the file /etc/sysconfig/network-scripts/ ifcfg-eno16777736 .

An interface restart is required to apply the new configuration. To restart the interface, use the ifdown-[ NIC ] and ifup-[ NIC ] commands.

verifing ip address update

To learn more about the nmtui utility, you check the following tutorial.

The nmtui Command and Utility on Linux

Using the nm-connection-editor graphical utility

The nm-connection-editor is a desktop tool. It works only on desktop. Open a terminal, and run the following command to start it.

From the opened window, select the appropriate NIC and click the Edit option

nm-connection-editor

Now use the following steps to add/update/edit IP configuration on the selected interface.

  • Switch to the IPv4 Settings.
  • Select the Manual option from the Method drop-down menu.
  • Click the Add button and configure IP addresses in respective fields.
  • Click the Save button.
  • Click the Close button on the main screen.

edit a connection

Restart the interface and verify the new IP configuration.

verify update

To learn more about the nm-connection-editor tool, you check the following tutorial.

The nm-connection-editor command on Linux

That's all for this tutorial. In this tutorial, we learned how to configure new IP addresses and manage existing IP addresses on Linux.

By ComputerNetworkingNotes Updated on 2023-10-06 02:00:02 IST

ComputerNetworkingNotes Linux Tutorials How to configure IP address in Linux

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us [email protected]

ip address assign linux

How to assign static IP address on Ubuntu Linux

Here are the steps to assign an IP address to an Ubuntu Server using the Settings app and Terminal commands.

Avatar for Mauro Huc

On Ubuntu (version 22.04, 21.04, or older releases), it’s possible to assign a static IP address through the Settings interface or the Terminal using commands, and in this guide, you will learn how.

Once you complete the installation of the Ubuntu Server (or client version), the device will receive a network configuration assigned automatically by the Dynamic Host Configuration Protocol (DHCP) server available in the local network. Although this configuration is enough to access the network and internet, it’s a good idea to assign a static network configuration as you probably are setting up the system to serve different services, such as file and print sharing and others.

The reason is that a dynamic configuration can change at any time, and a static network configuration is permanent, meaning that devices in the network will be able to always reach the server with the address.

This guide will teach you the steps to configure a static IP address for your Ubuntu Server installation. You can also use these instructions for the client version of the Linux distro.

Set static IP address configuration on Ubuntu Linux (GUI)

Set static ip address configuration on ubuntu linux (command).

To assign a static IP address on Ubuntu (server or client) through the Settings app, use these steps:

Open Settings .

Click on Network .

Click the Settings button for the “Wired” network interface.

Ubuntu network open settings

Click the IPv4 tab.

Select the Manual option for the “IPv4 Method” setting.

Under the “Addresses” section, confirm the static IP address in the “Address” setting — for example, 10.1.4.201.

Ubuntu assign static IP address

Confirm the subnet mask in the “Netmask” settings — for example, 255.255.255.0.

Confirm the gateway address (usually the router’s IP) in the “Gateway” setting.

Turn off the Automatic toggle switch for the “DNS” setting.

Confirm the DNS address(es) for this static configuration — for example, the router IP address or your preferred DNS address, such as the ones from Google Public DNS, 8.8.8.8, 8.8.4.4 .

(Optional) Click the IPv6 tab.

Select the Disable option in the “IPv6 Method” setting.

Click the Apply button.

(Optional) Turn off and on the Wired toggle switch on the “Network” page if the configuration isn’t working.

Once you complete the steps, the Linux distro will start using the new static network configuration.

To assign a static IP address on Ubuntu Linux (server or client), use these steps:

Open Terminal

Type the following command to determine the network interface name and press Enter :

Ubuntu view IP config command

Type the following command to open the configuration file and press Enter :

Copy and paste the following configuration (changing the TCP/IP settings with your settings):

In the command, change “ens33” for the name of your server network adapter name and “10.1.4.201/24” for the static IP address and subnet mask after the forward slash (/) you want to assign to the Ubuntu Server. For example, the “/24” assigns the “255.255.255.0” address. Also, change “8.8.4.4, 8.8.8.8” for static DNS addresses. The comma (,) is only required when setting up multiple addresses. And change “10.1.4.1” for the default gateway of your network (usually the router IP address).

Ubuntu static IP set commands

Press “Ctrl + O,” “Enter,” and “Ctrl + X” to save the changes and exit the text editor.

Type the following command to apply the new static IP address configuration and press Enter :

(Optional) Type the following command to confirm the static network configuration and press Enter :

Ubuntu confirm IP address

In the command, change “ens33” to the name of the adapter.

After you complete the steps, the static  IP address configuration will apply to the network adapter on Ubuntu (server or client).

  • How to backup config file on TrueNAS
  • How to create Windows Server bootable USB media

XDA Developers

How to set a static internal IP in Ubuntu

Quick links, how to set static internal ip in ubuntu using the gui, how to set static internal ip in ubuntu using the terminal and text editor.

There comes a time when you might have to configure Ubuntu or any other Linux distribution with a static IP address. While you can't change your external static IP address, since it's the one your internet service provider provides, you can change your internal one. This is the IP address used on your network inside your home or office.

Though many tasks on Ubuntu usually require you to visit the terminal app and deal with lines of text, changing your internal IP is easy. You can do this through the settings app and the Graphical User Interface (GUI). Of course, if you want, you can also swap things out by going through the terminal. Here's how.

Without any technical know-how or knowledge, you can set a static IP in Ubuntu through the settings app. Just note, you will have to use the terminal once to find a range of IP addresses that you can assign. Once you do that, you just tap the Windows Key or the Superkey on your device and search for Settings . Once the app is open, proceed with the steps below.

  • If you're connected to the internet via Wi-Fi, choose Wi-Fi . If you're connected via Ethernet, select Network.
  • Once the interface is open, click the settings icon next to the network you're connected to.
  • From the list of tabs at the top, choose IPv4.
  • Under ipv4 method, be sure to choose Manual.
  • Under Addresses, enter the IP address, the Netmask, and the Gateway you want to use. For finding IP addresses that'll work on your network, you can proceed with the steps below.
  • Open a terminal session. With Ctrl, Alt, and T. Install net-tools with the command sudo apt install net-tools.
  • In this case, we have an inet of 192.168.1.176 and a netmask of 255.255.255.0. We can enter those numbers and can calculate the usable range using this website .
  • When you've calculated the usable range of addresses, choose a valid IP address that falls within this range. Then, you can click Apply at the top.

Any changes you apply will automatically go into effect. If you want, you can also use the terminal to confirm your IP address. Launch it with Ctrl, Alt, and T on your keyboard. Once launched, enter the command ip addr or ip a . You should see an interface IP address listed.

If you're a bit more technical and want to set a static IP in Ubuntu using the terminal, that is possible. You'll have to edit some lines of text and go through a few extra steps, but here's how:

  • Display information about your network. Use the command nmcli connection show. You'll see a network name, a UUID, a Type, and a Device. If this package isn't installed (though it should be, as it comes preinstalled with Ubuntu), then run sudo apt-get install network-manager
  • Note down the range of IP addresses you'll be able to use. Use the command ip addr to find out your machine's current IP address. This tutorial assumes that your network adapter is called enp0s3. If it isn't, then look for the correct one and also change the interface names in the subsequent commands. In the above example, we have an inet of 10.0.2.15, with the /24 denoting that the network uses a 255.255.255.0 subnet mask. In most cases, your usable network range will be whatever is in the first three places of the internal IP address, and then any unused number on your network between 1 and 255 in the last section. For example, we can use 10.0.2.16. If you're unsure, you can enter the subnet mask and your internal IP address into this website to calculate the usable range.
  • Note the IP address of your default gateway with the command ip r. In our example, it's 10.2.2.2.
  • Next, we'll add a new static connection option. Run the following command, making sure to change the numbers after "ip4" and "gw4" depending on your network conditions. These are the IP address you want to change your machine to and the current default gateway, respectively. sudo nmcli con add con-name "static" ifname enp0s3 type ethernet ip4 10.0.2.13/24 gw4 10.0.2.2 In our case, we do the following.
  • Set your DNS, manual DHCP (so, a static IP), and enable the connection. You can do that by running the following commands in succession. nmcli con mod "static" ipv4.dns "1.1.1.1,8.8.8.8" You can swap out the DNS servers above for whatever you want, they are in order of primary and secondary. nmcli con mod "static" ipv4.method manual; nmcli con up "static" ifname enp0s3 Once done, you can run nmcli con show to see if the new connection is enabled. If the output above looks like yours, then you're ready to go!

Setting complete

That's all you need to set up a static IP in Ubuntu. It doesn't take much effort. Remember, we're always writing about Linux, so you can check out our guide to the best Linux laptops should you need one.

How to set a static internal IP in Ubuntu

'ZDNET Recommends': What exactly does it mean?

ZDNET's recommendations are based on many hours of testing, research, and comparison shopping. We gather data from the best available sources, including vendor and retailer listings as well as other relevant and independent reviews sites. And we pore over customer reviews to find out what matters to real people who already own and use the products and services we’re assessing.

When you click through from our site to a retailer and buy a product or service, we may earn affiliate commissions. This helps support our work, but does not affect what we cover or how, and it does not affect the price you pay. Neither ZDNET nor the author are compensated for these independent reviews. Indeed, we follow strict guidelines that ensure our editorial content is never influenced by advertisers.

ZDNET's editorial team writes on behalf of you, our reader. Our goal is to deliver the most accurate information and the most knowledgeable advice possible in order to help you make smarter buying decisions on tech gear and a wide array of products and services. Our editors thoroughly review and fact-check every article to ensure that our content meets the highest standards. If we have made an error or published misleading information, we will correct or clarify the article. If you see inaccuracies in our content, please report the mistake via this form .

What is SSH and how do you use it? The secure shell basics you need to know

jack-wallen

If you ever have to do any remote administration, at some point you're going to have to log into a Linux server and get to work. To do that, you're going to need to use SSH (aka Secure Shell). For those that have never been exposed to such a tool, you're in for a treat because it not only makes logging into remote systems easy, but it's also very secure.

What is SSH?

SSH is a secure means of logging into a remote machine. Once logged in, you can run any command you need to work with the server. Before you think that using SSH is difficult, fret not. Using SSH is not only fairly easy, but it's also really quite powerful. 

How to use SSH to connect to a remote server  

What you'll need:  I want to walk you through the first steps of using SSH. I'll be demonstrating on Pop!_OS Linux but this information will work on any distribution of Linux that supports SSH (which is most of them). The only things you'll need to follow along with this tutorial are two running instances of Linux. That's it. Let's get busy with SSH. 

1. Log in to a remote machine

Using SSH makes it possible for you to log in from a local machine to a remote machine. You'll need user accounts on both machines. Those accounts don't have to be the same on each machine (I'll explain this in a minute), but you do need to have login credentials for both.

Also: Do you need antivirus on Linux?

You will also need the IP address (or domain) of the server you want to log into. Let's say, for example's sake, our remote server is at IP address 192.168.1.11 and our user account is the same on both machines. Log into your desktop computer, open a terminal window, and log in to the remote machine with the command:

You will be prompted for your username on the remote machine. Once you've successfully authenticated with the password, you'll be logged into the remote machine, where you can start working.

2. Log in via domain name

Let's say the remote machine is associated with the domain www.example.com. You could log into that with the command:

3. Log in using a different user name

Now, what if your username on the remote machine isn't the same as the one on the desktop? If your username on the remote machine is olivia, you could log in with the command:

You will be prompted for olivia's password (not the local user's).

4. Log in via a non-standard port

Normally, SSH uses port 22. Some administrators might change that port (for security purposes). If the server administrator has configured SSH to listen to port 2022, you can't simply type the standard SSH command to log in. Instead, you have to add the -p (for  port ) option like so:

SSH Site configuration

Remembering all of those IP addresses and usernames can be a real headache for some. Fortunately, SSH makes it possible for you to create a configuration file that houses all of this information. Say, for example, you have the following list of servers you log into:

  • webserver - 192.168.1.11
  • email server - 192.168.1.12
  • database server - 192.168.1.13

Let's configure SSH such that you would only have to log in with the commands:

1. Create a config file

We'll also assume that the user on web1 is olivia, the user on email1 is nathan, and the user on db1 is the same as the user on the local machine. To set this up, we must create a config file in the ~/.ssh directory. For that, go back to the terminal window on your local machine and issue the command:

Where USER is your Linux username.

2. Configure the file

In that file, add the following lines:

Save and close the file. You should now be able to log into those different servers with the shorter commands (i.e. ssh web1, ssh email1, and ssh db1). It's important to remember, however, that for web1 you'll be prompted for olivia's password, email1 will ask for nathan's password, and db1 will ask for the same user as the local one.

Running commands on a remote machine with SSH

This is a handy little trick. Let's say you don't necessarily want to log into a remote machine but you do need to run a command. For example, you want to list out the contents of the remote user's home directory. For that, you could issue the command:

Since we've set up our config file, we can truncate that command to:

We can cut off a bit more from that command because Linux has a shortcut for a user's home directory (because /home/olivia and ~/ are the same things). For that, our command becomes:

And that, my dear friends, is the basics of using SSH to log into a remote Linux machine. If you ever have to do any remote administration of a Linux machine, this is what you'll need to know. Next time around, I'll introduce you to SSH Key Authentication, for even more secure remote logins.

 width=

What is deep learning? Everything you need to know

 width=

Learn all about ChatGPT with this $20 course

 width=

Automate your photo and video backups with this $280 deal

  • Privacy news

Tips & tricks

  • ExpressVPN news

How to configure a static IP address

' src=

Felipe Allende

ip address assign linux

A static IP address can be very useful in some cases, and can even improve your security. If you want to set up a local server or improve your internet speeds, configuring a static IP address on different devices is a very simple process. In this article, we’ll guide you through the steps so you can have a working static IP address in no time.

Note that ExpressVPN does not offer static IP addresses at the moment. This article is only informational on how you might set one up.

What is a static IP?

An IP address is a unique series of numbers that identifies each device on a local network or the internet. An IP address can be dynamic or static.

Most people use dynamic IP addresses, which change automatically and regularly—most commonly every 24 hours or after a router reset . This means when you go online, your IP address should be different from the one you had the day before.

A static IP address, also called a dedicated IP address, doesn’t change. This means whenever you connect to the internet after disconnecting, you’ll get the same IP address. It usually costs extra to get a static IP address. 

And while dynamic IP addresses generally offer greater privacy and security for the average user, static IP addresses can be useful for certain systems.

Why you may want a static IP address

Most residential internet services use a dynamic IP configuration through DHCP (Dynamic Host Configuration Protocol). While a static IP address could be the best approach in some cases, it’s important that you know what they are good for, and see if you’re in one of these use cases. Here are the most common ones:

You want to host a server For hosting game, web, email, or other types of servers, a static IP provides a consistent address for users to connect to, making connections easy.

Your IoT device requires it Some Internet of Things (IoT) devices require static IPs to function correctly and remain consistently accessible for monitoring and control.

You want a more stable connection File downloads and uploads tend to be slightly faster with a static IP.

You want more security Static IPs facilitate the implementation of security measures like IP whitelisting, ensuring only authorized devices can access certain online services.

You want to simplify your network management

Assigning static IPs to devices makes network management easier, allowing for straightforward identification, troubleshooting, and configuration of networked devices.

How to set up a static IP address

Setting up a static IP address is fairly simple but varies per device. However, the first thing you should sort out before configuring is the static IP address itself. You would inquire with your internet service provider (ISP) about getting a static IP , which usually involves a small extra charge.

How to set a static IP address on a router

You can assign a static IP address through your router for any device on its network. To do this, you’ll need the MAC address of whatever device you want to configure with a static IP address, and that device must be connected to the router. Lastly, note that most routers have different software, so these are general instructions to get you started. 

  • Access the router. Open a web browser and enter your router’s IP address into the address bar. You can usually find this on the back of your router or in the manual.
  • Log in. Enter your username and password to log into the router’s admin panel. If you haven’t changed these from the defaults, they should also be on the router or manual.
  • Navigate to LAN settings. Look for a section in the admin panel labeled “LAN” or “Network Settings”. This might be under “Advanced Settings” depending on your router.
  • Find DHCP or static IP settings. Locate the DHCP settings within the LAN or Network Settings. You may need to switch from DHCP to Manual or Static IP configuration.
  • Fill in the IP address , Gateway , Network prefix length , and DNS fields.
  • Save and apply. After entering all necessary information, save and apply your changes. The router may need to restart for changes to take effect.

How to set a static IP address on Windows 10

Assigning a static IP to your Windows 10 device is much easier than on your router. Just follow these instructions:

  • Go to Settings. Press the Windows key, type “Settings,” and press Enter.
  • Click Network and Internet and then Network and Sharing Center .
  • Click Change adapter settings on the left pane.
  • Right-click your network connection and select Properties .
  • Highlight Internet Protocol Version 4 (TCP/IPv4) and click on Properties .
  • Fill in the IP address, Gateway, Network prefix length, and DNS fields.
  • Click OK to save your changes, then click OK again to exit the properties menu.

How to set a static IP address on Windows 11

The steps for Windows 11 are very similar to those on Windows 10:

  • Open Settings. Click on the Start menu, select Settings, or press Windows + I on your keyboard.
  • In the Settings menu, click on Network & Internet .
  • Choose the network you are connected to. If you are using Wi-Fi, click on “Wi-Fi” and then select your network. For a wired connection, click on “Ethernet” and then on your network connection.
  • Edit IP Assignment. Scroll down and click on “Hardware properties.” Then, find the “IP assignment” section and click the “Edit” button.
  • Change to Manual. In the “Edit IP settings” window, change the setting from “Automatic (DHCP)” to “Manual.” Toggle on the “IPv4” switch to enable manual IP configuration.
  • Click Save to apply your settings.

How to set a static IP address on macOS

To configure a static IP on your Mac, follow these steps:

1. Click on the Apple menu in the top left corner of your screen and select System Preferences .

ip address assign linux

2. In the System Preferences window, find and click on Network .

3. Select the network connection you wish to configure from the list on the left side. This could be either Wi-Fi or Ethernet, depending on how your Mac is connected to the network.

ip address assign linux

4. With the network selected, click on the Details button in the top right corner of the window.

ip address assign linux

5. Click on the TCP/IP tab on the left.

6. Click on the dropdown menu next to “Configure IPv4” and select Manually from the list of options.

ip address assign linux

7. Fill in the IPv4 Address field with the static IP address you want to assign to your Mac. 

8. Optionally, navigate to the DNS tab in the same window to manually enter DNS server addresses if required.

9. Click OK to close the Details settings window.

How to set a static IP address on Android

Setting up a static IP address on Android is straightforward. Just follow these steps:

  • Tap on the Settings icon on your home screen or app drawer.
  • Scroll down and tap on Wi-Fi . Ensure Wi-Fi is turned on, and you’re connected to the network you want to configure.
  • Select the gear icon beside your current network.
  • Find the IP settings section and change it from DHCP to Static .
  • Scroll down and tap Save to apply your new static IP settings.

How to set a static IP address on iOS

On iOS, the process is quite similar. Follow these instructions:

1. Tap the Settings icon on your home screen or App Library.

ip address assign linux

2. Next to the Wi-Fi network you’re connected to, tap the i icon to access the network’s settings.

ip address assign linux

3. Scroll down and tap on Configure IP to change how your device acquires an IP address.

ip address assign linux

4. Tap Manual to switch from automatic (DHCP) to manual IP settings.

ip address assign linux

5. Fill in the IP address , Gateway , Network prefix length , and DNS fields.

6. Tap Save in the upper right corner to apply your changes.

How to set a static IP address on Linux

The process for Linux is a little more involved. Bear in mind that while you could do it by running a ip adr command, that change would be reversed with every reboot. To set up the static IP permanently, follow these steps:

  • Press Ctrl + Alt + T to open the terminal on your Linux desktop.
  • Use the command ip addr or ifconfig to identify your network interface.
  • Navigate to Netplan Configuration. Files are typically located in /etc/netplan/. Use ls /etc/netplan/ to list the configuration files.
  • Use a text editor like nano or vim to edit the YAML configuration file found in the previous step.
  • Modify the file to include your static IP settings under the appropriate network interface.
  • Save the file and apply the changes by running sudo netplan apply .

How to set a static IP address on Raspberry Pi

Like with Linux, the process with Raspberry Pi is more involved than with other platforms. To configure the static IP, follow these steps:

  • Access the terminal directly or via SSH if you’re remotely connected to your Raspberry Pi.
  • Type sudo nano /etc/dhcpcd.conf to edit the DHCP client configuration file with nano editor. You can replace nano with your preferred text editor.
  • Scroll to the end of the file and add your static IP configuration.
  • Press Ctrl + O to save the changes, then Ctrl + X to exit nano.
  • To apply the changes, restart the DHCP client daemon with sudo service dhcpcd restart.

The differences between static and dynamic IP addresses

Static and dynamic IP addresses serve the fundamental role of identifying devices on a network, yet they differ in management, purpose, and application. Here’s a comparison:

Does ExpressVPN offer static or dynamic IPs?

ExpressVPN provides dynamic IPs and doesn’t offer static IPs at the moment. 

This means every time you connect to ExpressVPN, you are given a different IP address. (That said, it is possible to repeatedly get the same IP if you happen to connect to the same server multiple times.) The IP you are given should indicate to websites and apps that you are located in the country of your choosing. Moreover, every IP is shared by numerous ExpressVPN users at the same time, increasing your anonymity even more.

Phone protected by ExpressVPN.

Mask your IP address with a VPN

30-day money-back guarantee

A phone with a padlock.

Enjoy a safer online experience with powerful privacy protection

' src=

Like what you have read?

Clap for this post. Or share your thoughts!

Subscribe to the weekly blog newsletter

Get the latest in privacy news, tips, tricks, and security guides to level-up your digital security.

ip address assign linux

  • Related posts
  • Featured Posts
  • More from the author

ip address assign linux

4 easy ways to change the location on your iPhone

ip address assign linux

How to use Private Browsing on your iPhone in 2024

ip address assign linux

How to change your home address on an iPhone

How to change location on Facebook Marketplace

How to change location on Facebook Marketplace

Tech Friend Edition 2

Tech Friend: My VPN location seems to be wrong

Dynamic MTU to fix VPN browsing issues.

Dynamic MTU: How we fixed a common cause of browsing problems

Alternative apps to Omegle that let you chat with random strangers.

Best Omegle alternatives to chat with strangers

Phone with location pin and luggage handles.

How to track your own luggage

21 best onion and Tor sites on the dark web

Dark Web Links: The best .onion and Tor sites in 2024

streaming push play button

Best new shows and movies to stream in February 2024

Tech Friend talks cheap phones.

Tech Friend: 5 great phones under 400 USD

ip address assign linux

Can you stop someone from mirroring your phone?

ip address assign linux

Why is the Chrome browser so slow?

ip address assign linux

Is someone spying on your phone?

ip address assign linux

Tech Friend: Help! My phone is overrun with ads

Leave a comment cancel reply.

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

ExpressVPN is proudly supporting

logo_1

Subscribe to the blog newsletter

Choose language.

ip address assign linux

6 Linux commands to find Public IP addresses for your machine

Do you want to find the public IP address of your cloud server or any machine running with Linux distros such as Ubuntu, RHEL, AlmaLinux, Oracle, Debian, etc? Then the commands given in this article will surely help you a lot.

Finding the public IP address of your machine becomes necessary if you want to access some web application, set up remote access, do some troubleshooting work, or just for your knowledge want to know your machine’s virtual footprint. Here, we discuss how to use simple tools like curl and wget to network utilities like dig and nslookup to look for public IP addresses, each command offers a unique approach to revealing this essential detail.

Well, we can check our Private addresses simply by using the “ ip a” command but for public addresses, here are the commands to follow:

Curl is the default command utility available in almost all Linux out of the box and even if not then installation of cURL is quite easy. But do you know we can use it to fetch the details of our Public IP address attached to our Server? For example, we can use the CURL to get the details from “ifconfig.me “, here is the way to use it.

For Ipv4 public address:

To get an Ipv6 public IP address:

Note : “ -w “\n ” in the command is just to get the output in the next line, followed by the command prompt. If you want, you can use the command without it. Whereas -4 represents IPv4 and -6 for IPv6 addresses.

In the given screenshot, first, we identified our AWS Cloud server running Ubuntu Linux’s private IP address and then used the “ cURL ” command to get Public IP addresses – Ipv4 and Ipv6.

use curl to check Linux public IP address

If you don’t want to use the cURL and have “ wget ” on your system already then that can be used similarly to retrieve our public IP address with the help of ipecho.net service and print it to the terminal.

use Wget to get public Ipaddress

The dig is another popular command to find the public address of a particular domain name or simply your own. In the given command the “ dig ” will ask for the IP address of the domain myip.opendns.com from an OpenDNS resolver i.e “ resolver1.opendns.com ” which in return sends back the public IP address of the user who requested instead of myip.opendns.com because it is programmed in such as way.

4. nslookup

Instead of the “ dig ” command, we can use nslookup which works similarly to fetch the public IP address from the OpenDNS resolver. nslookup performs a DNS lookup for the myip.opendns.com domain using the OpenDNS resolver.

To get IPV4 using nslookup:

nslookup command to find public address

In this list of commands to find the Public IP address of your server or desktop another name is “ host ” like nslookup you can use it as well. Let’s see how to use it.

Ipv4 will be provided:

IPv6 will be in the output:

host command to get IP address public sever

6. ipconfig.io or ipinfo.io

Again if the first command given in this list that uses cURL is not working for you then you can go for the given ones:

You can add the -4 option in the above-given commands to get the IPv4 address.

So, these were a few commands we can use on our Linux server or desktop to quickly identify and note the Public IP address to perform some networking tasks or troubleshooting.

Other Articles:

How to find the IP address of a Guest in VirtualBox?

  • Installing CyberPanel on Ubuntu 22.04 LTS Linux Server

Use Cockpit as Virt-Manager alternative to manage KVM VMs

5 Commands to list IP Address Information on Ubuntu

5 Commands to list IP Address Information on Ubuntu

Newly installed Bitnami Ghost blog keeps redirecting to the LocalHost

Newly installed Bitnami Ghost blog keeps redirecting to the LocalHost

How to install KVM on Oracle Linux 9?

How to install KVM on Oracle Linux 9?

How to Install Cockpit-Podman for Container Management on Linux

How to Install Cockpit-Podman for Container Management on Linux

Leave a Comment Cancel reply

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

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

How to install RHEL on the Marvell Octeon 10 DPU

RHEL

The surge in networking demands and cost has piqued interest in data processing units (DPUs). The Marvell Octeon 10 DPU addresses these challenges with their hardware solution. Red Hat Enterprise Linux (RHEL) excels at running everywhere from the public cloud to the edge. Bringing RHEL onto the Marvell Octeon 10 DPU is the first step in realizing and building a vibrant ecosystem for open source collaboration in solving these challenges. Red Hat along with its ecosystem partners can plan and bring their solutions onto the Marvell Octeon 10 DPU.

Installing RHEL on Marvell Octeon 10

Welcome to this guide to installing Red Hat Enterprise Linux on the Marvell Octeon 10 DPU. This article will guide you through the process of setting up RHEL on the Marvell Octeon 10 using the 10G management interface and a PXE server on the host machine.

Info alert: Note

Important: Please note that it is assumed that the UEFI Bootloader is flashed correctly onto the secondary SPI memory device. If not, please contact your Marvell FAE to be given the instructions to do so. You only need to flash the UEFI Bootloader once unless there are bug fixes or improvements provided by Marvell.

Overview of the setup

When it comes to installing RHEL on the Marvell Octeon 10, a PXE server can be set up either on the network or on the host machine itself. The advantage of choosing the latter is that the management network is looped back to the host itself. Also the host will have access to the serial terminal via USB. This self-contained approach simplifies the provisioning process, making it more accessible and user-friendly for small scale deployments (typically one node). Figure 1 shows the setup.

Host and Marvell Octeon 10 setup diagram.

Components of the setup:

  • UEFI Bootloader flashed on the Marvell Octeon 10
  • RHEL installation on x86 host with minicom
  • RHEL iso (downloaded through your Red Hat subscription)
  • Custom GRUB configuration
  • Custom kickstart configuration
  • TFTP server
  • DHCP server
  • HTTP server

Setting up DHCP

The DHCP server for the purposes of this document of installing RHEL will be used to give the UEFI bootloader an IP address when attempting to PXE boot the ISO image through TFTP. (Note: This DHCP server can also be used by U-Boot to burn the UEFI bootloader onto the secondary SPI memory device on the Marvell Octeon 10).

Start by installing the DHCP server for RHEL on the host:

For the interface directly connected to the 10G management port on the Marvell Octeon 10, assign the ip address "172.131.100.1/24" to it

Create/change the dhcpd config at /etc/dhcp/dhcpd.conf to the following. Please replace the DNS servers and domain with your own:

Restart DHCPD with the following command:

After restarting, make sure that DHCPD is running properly:

Setting up TFTP

The DHCP server for the purposes of this document of installing RHEL will be used to provide the Linux kernel, Init RAM disk, GRUB EFI, and the custom GRUB config to the UEFI Bootloader.

Start by installing the TFTP server for RHEL on the host:

Unfortunately the TFTP client in the UEFI bootloader does not support options properly thus we need to modify the TFTP server on the host with the -B option in the file /usr/lib/systemd/system/tftp.service :

Change the ExecStart line from:

Then restart the TFTP server service file:

After restarting, make sure that TFTP is running properly:

Setting up the mandatory PXE files

Please make sure that the DHCP and TFTP servers are running correctly. Following the steps above.

Firstly, download the RHEL iso from your RH subscription. Note that you need the AARCH version of the RHEL ISO since the Marvell Octeon 10 uses the ARM architecture. Mount the ISO:

Create a TFTP boot directory and copy the necessary files:

Create a custom GRUB configuration at /var/lib/tftpboot/grub.cfg where 172.131.100.1 is the IP of the host interface connected to the 10G management port of the Octeon 10 DPU. Firstly the Grub EFI ( grubaa64.efi ) is loaded via the PXE options from DHCP. Then the GRUB config is read and the Linux kernel ( vmlinuz ) and Init RAM disk ( initrd.img ) is loaded from TFTP.

This GRUB configuration references where the repo and kickstart files would be found via an HTTP webserver. The vmlinuz and initrd.img are made available already from the TFTP boot directory (/var/lib/tftpboot/pxelinux) .

We will be using Python's HTTP server for convenient start and stop of the webserver. Please make sure Python is installed:

Now let's prepare the files for HTTP. We will create a /www webserver directory and statically link the mounted ISO to the webserver directory. The mounted ISO being statically linked to the webserver will provide the RHEL installer with additional packages.

Create a new kickstart file under /www/kickstart.ks :

Note that the interface enP2p6s0 should be the 10G management port. Change myrootpassword with your own desired root password. Also this will install on the NVME drive. This must be populated prior to the card being seated into the server.

Optional: A useful tool called ksvalidator can be used to validate the kickstart.ks file:

Now we can start the HTTP server.

Installing via UEFI PXE boot on the 10G management port

The steps above should have prepared the necessary files and servers running to PXE boot. Make sure all the steps above are performed and the DHCP, TFTP, and HTTP servers are running.

First, you should install minicom:

Find which USB devices from the Marvell Octeon 10 are connected to the HOST:

From this output, ttyUSB0 and ttyUSB1 are associated with the Marvell Octeon 10. The ttyUSB1 device is used to reset the Marvell Octeon 10 in the case of failure. The ttyUSB0 device is the serial terminal to the Marvell Octeon 10. This will be the device we will use to launch PXE Boot from UEFI.

Warning alert: Warning

Important: The Marvell Octeon 10 has issues with the Hardware Flow Control. Make sure this option is set to No via “ O - cOnfigure Minicom -> Serial port setup -> F - Hardware Flow Control : No ”. Also make sure the baud rate “ E - Bps/Par/Bits : 115200 8N1 ” is set correctly.

Reboot the Marvell Octeon 10 via ttyUSB1 or by typing reboot in the BuildRoot OS.

When you see Press 'B' within 10 seconds for boot menu , press the B key immediately.

Then choose 2) Boot from Secondary Boot Device :

When the UEFI Bootloader is running, hit the < ESC > key when you see the following message:

The following menu should now be visible:

Move to the Boot Manager and press < ENTER >. Then move through the menu until you hit an interface with the MAC address 80AA9988776A and the UEFI PXEv4 option.

When this option is selected by pressing < ENTER >, the installation of RHEL should start.

The Marvell Octeon 10 will reboot into the fresh RHEL environment after the installation completes.

Demo of RHEL running on the DPU

Showing the CPU information:

We can install ARM packages using dnf :

We can see the available interfaces (including PF and VF) on the DPU:

Running ethtool on some interfaces to show PFs and VFs available on the DPU:

Appendix 1: Resetting the Marvell Octeon 10 DPU

Enter the other USB device for the Marvell Octeon 10 DPU:

Enter the M) Management commands:

Enter the r) Chip reset to reset the Marvell Octeon 10 DPU.

  • Red Hat Enterprise Linux
  • Red Hat OpenShift
  • Red Hat Ansible Automation Platform
  • See all products
  • See all technologies
  • Developer Sandbox
  • Developer Tools
  • Interactive Tutorials
  • API Catalog
  • Operators Marketplace
  • Learning Resources
  • Cheat Sheets

Communicate

  • Contact sales
  • Find a partner

Report a website issue

  • Site Status Dashboard
  • Report a security problem

RED HAT DEVELOPER

Build here. Go anywhere.

We serve the builders. The problem solvers who create careers with code.

Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

Red Hat legal and privacy links

  • About Red Hat
  • 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

docker run (docker container run)

Create and run a new container from an image

The following commands are equivalent and redirect here:

  • docker container run

Description

The docker run command runs a command in a new container, pulling the image if needed and starting the container.

You can restart a stopped container with all its previous changes intact using docker start . Use docker ps -a to view a list of all containers, including those that are stopped.

Assign name (--name)

The --name flag lets you specify a custom identifier for a container. The following example runs a container named test using the nginx:alpine image in detached mode .

You can reference the container by name with other commands. For example, the following commands stop and remove a container named test :

If you don't specify a custom name using the --name flag, the daemon assigns a randomly generated name, such as vibrant_cannon , to the container. Using a custom-defined name provides the benefit of having an easy-to-remember ID for a container.

Moreover, if you connect the container to a user-defined bridge network, other containers on the same network can refer to the container by name via DNS.

Capture container ID (--cidfile)

To help with automation, you can have Docker write the container ID out to a file of your choosing. This is similar to how some programs might write out their process ID to a file (you might've seen them as PID files):

This creates a container and prints test to the console. The cidfile flag makes Docker attempt to create a new file and write the container ID to it. If the file exists already, Docker returns an error. Docker closes this file when docker run exits.

PID settings (--pid)

By default, all containers have the PID namespace enabled.

PID namespace provides separation of processes. The PID Namespace removes the view of the system processes, and allows process ids to be reused including PID 1.

In certain cases you want your container to share the host's process namespace, allowing processes within the container to see all of the processes on the system. For example, you could build a container with debugging tools like strace or gdb , but want to use these tools when debugging processes within the container.

Example: run htop inside a container

To run htop in a container that shares the process namespac of the host:

Run an alpine container with the --pid=host option:

Install htop in the container:

Invoke the htop command.

Example, join another container's PID namespace

Joining another container's PID namespace can be useful for debugging that container.

Start a container running a Redis server:

Run an Alpine container that attaches the --pid namespace to the my-nginx container:

Install strace in the Alpine container:

Attach to process 1, the process ID of the my-nginx container:

UTS settings (--uts)

The UTS namespace is for setting the hostname and the domain that's visible to running processes in that namespace. By default, all containers, including those with --network=host , have their own UTS namespace. Setting --uts to host results in the container using the same UTS namespace as the host.

Note Docker disallows combining the --hostname and --domainname flags with --uts=host . This is to prevent containers running in the host's UTS namespace from attempting to change the hosts' configuration.

You may wish to share the UTS namespace with the host if you would like the hostname of the container to change as the hostname of the host changes. A more advanced use case would be changing the host's hostname from a container.

IPC settings (--ipc)

The --ipc flag accepts the following values:

If not specified, daemon default is used, which can either be "private" or "shareable" , depending on the daemon version and configuration.

System V interprocess communication (IPC) namespaces provide separation of named shared memory segments, semaphores and message queues.

Shared memory segments are used to accelerate inter-process communication at memory speed, rather than through pipes or through the network stack. Shared memory is commonly used by databases and custom-built (typically C/OpenMPI, C++/using boost libraries) high performance applications for scientific computing and financial services industries. If these types of applications are broken into multiple containers, you might need to share the IPC mechanisms of the containers, using "shareable" mode for the main (i.e. "donor") container, and "container:<donor-name-or-ID>" for other containers.

Full container capabilities (--privileged)

The following example doesn't work, because by default, Docker drops most potentially dangerous kernel capabilities, including CAP_SYS_ADMIN (which is required to mount filesystems).

It works when you add the --privileged flag:

The --privileged flag gives all capabilities to the container, and it also lifts all the limitations enforced by the device cgroup controller. In other words, the container can then do almost everything that the host can do. This flag exists to allow special use-cases, like running Docker within Docker.

Set working directory (-w, --workdir)

The -w option runs the command executed inside the directory specified, in this example, /path/to/dir/ . If the path doesn't exist, Docker creates it inside the container.

Set storage driver options per container (--storage-opt)

This (size) constraints the container filesystem size to 120G at creation time. This option is only available for the btrfs , overlay2 , windowsfilter , and zfs storage drivers.

For the overlay2 storage driver, the size option is only available if the backing filesystem is xfs and mounted with the pquota mount option. Under these conditions, you can pass any size less than the backing filesystem size.

For the windowsfilter , btrfs , and zfs storage drivers, you cannot pass a size less than the Default BaseFS Size.

Mount tmpfs (--tmpfs)

The --tmpfs flag lets you create a tmpfs mount.

The options that you can pass to --tmpfs are identical to the Linux mount -t tmpfs -o command. The following example mounts an empty tmpfs into the container with the rw , noexec , nosuid , size=65536k options.

For more information, see tmpfs mounts .

Mount volume (-v)

The example above mounts the current directory into the container at the same path using the -v flag, sets it as the working directory, and then runs the pwd command inside the container.

As of Docker Engine version 23, you can use relative paths on the host.

The example above mounts the content directory in the current directory into the container at the /content path using the -v flag, sets it as the working directory, and then runs the pwd command inside the container.

When the host directory of a bind-mounted volume doesn't exist, Docker automatically creates this directory on the host for you. In the example above, Docker creates the /doesnt/exist folder before starting your container.

Mount volume read-only (--read-only)

You can use volumes in combination with the --read-only flag to control where a container writes files. The --read-only flag mounts the container's root filesystem as read only prohibiting writes to locations other than the specified volumes for the container.

By bind-mounting the Docker Unix socket and statically linked Docker binary (refer to get the Linux binary ), you give the container the full access to create and manipulate the host's Docker daemon.

On Windows, you must specify the paths using Windows-style path semantics.

The following examples fails when using Windows-based containers, as the destination of a volume or bind mount inside the container must be one of: a non-existing or empty directory; or a drive other than C: . Further, the source of a bind mount must be a local directory, not a file.

For in-depth information about volumes, refer to manage data in containers

Add bind mounts or volumes using the --mount flag

The --mount flag allows you to mount volumes, host-directories, and tmpfs mounts in a container.

The --mount flag supports most options supported by the -v or the --volume flag, but uses a different syntax. For in-depth information on the --mount flag, and a comparison between --volume and --mount , refer to Bind mounts .

Even though there is no plan to deprecate --volume , usage of --mount is recommended.

Publish or expose port (-p, --expose)

This binds port 8080 of the container to TCP port 80 on 127.0.0.1 of the host. You can also specify udp and sctp ports. The Networking overview page explains in detail how to publish ports with Docker.

Note If you don't specify an IP address (i.e., -p 80:80 instead of -p 127.0.0.1:80:80 ) when publishing a container's ports, Docker publishes the port on all interfaces (address 0.0.0.0 ) by default. These ports are externally accessible. This also applies if you configured UFW to block this specific port, as Docker manages its own iptables rules. Read more

This exposes port 80 of the container without publishing the port to the host system's interfaces.

Publish all exposed ports (-P, --publish-all)

The -P , or --publish-all , flag publishes all the exposed ports to the host. Docker binds each exposed port to a random port on the host.

The -P flag only publishes port numbers that are explicitly flagged as exposed, either using the Dockerfile EXPOSE instruction or the --expose flag for the docker run command.

The range of ports are within an ephemeral port range defined by /proc/sys/net/ipv4/ip_local_port_range . Use the -p flag to explicitly map a single port or range of ports.

Set the pull policy (--pull)

Use the --pull flag to set the image pull policy when creating (and running) the container.

The --pull flag can take one of these values:

When creating (and running) a container from an image, the daemon checks if the image exists in the local image cache. If the image is missing, an error is returned to the CLI, allowing it to initiate a pull.

The default ( missing ) is to only pull the image if it's not present in the daemon's image cache. This default allows you to run images that only exist locally (for example, images you built from a Dockerfile, but that have not been pushed to a registry), and reduces networking.

The always option always initiates a pull before creating the container. This option makes sure the image is up-to-date, and prevents you from using outdated images, but may not be suitable in situations where you want to test a locally built image before pushing (as pulling the image overwrites the existing image in the image cache).

The never option disables (implicit) pulling images when creating containers, and only uses images that are available in the image cache. If the specified image is not found, an error is produced, and the container is not created. This option is useful in situations where networking is not available, or to prevent images from being pulled implicitly when creating containers.

The following example shows docker run with the --pull=never option set, which produces en error as the image is missing in the image-cache:

Set environment variables (-e, --env, --env-file)

Use the -e , --env , and --env-file flags to set simple (non-array) environment variables in the container you're running, or overwrite variables defined in the Dockerfile of the image you're running.

You can define the variable and its value when running the container:

You can also use variables exported to your local environment:

When running the command, the Docker CLI client checks the value the variable has in your local environment and passes it to the container. If no = is provided and that variable isn't exported in your local environment, the variable is unset in the container.

You can also load the environment variables from a file. This file should use the syntax <variable>=value (which sets the variable to the given value) or <variable> (which takes the value from the local environment), and # for comments. Lines beginning with # are treated as line comments and are ignored, whereas a # appearing anywhere else in a line is treated as part of the variable value.

Set metadata on container (-l, --label, --label-file)

A label is a key=value pair that applies metadata to a container. To label a container with two labels:

The my-label key doesn't specify a value so the label defaults to an empty string ( "" ). To add multiple labels, repeat the label flag ( -l or --label ).

The key=value must be unique to avoid overwriting the label value. If you specify labels with identical keys but different values, each subsequent value overwrites the previous. Docker uses the last key=value you supply.

Use the --label-file flag to load multiple labels from a file. Delimit each label in the file with an EOL mark. The example below loads labels from a labels file in the current directory:

The label-file format is similar to the format for loading environment variables. (Unlike environment variables, labels are not visible to processes running inside a container.) The following example shows a label-file format:

You can load multiple label-files by supplying multiple --label-file flags.

For additional information on working with labels, see Labels .

Connect a container to a network (--network)

To start a container and connect it to a network, use the --network option.

The following commands create a network named my-net and adds a busybox container to the my-net network.

You can also choose the IP addresses for the container with --ip and --ip6 flags when you start the container on a user-defined network. To assign a static IP to containers, you must specify subnet block for the network.

If you want to add a running container to a network use the docker network connect subcommand.

You can connect multiple containers to the same network. Once connected, the containers can communicate using only another container's IP address or name. For overlay networks or custom plugins that support multi-host connectivity, containers connected to the same multi-host network but launched from different Engines can also communicate in this way.

Note The default bridge network only allow containers to communicate with each other using internal IP addresses. User-created bridge networks provide DNS resolution between containers using container names.

You can disconnect a container from a network using the docker network disconnect command.

For more information on connecting a container to a network when using the run command, see the " Docker network overview " .

Mount volumes from container (--volumes-from)

The --volumes-from flag mounts all the defined volumes from the referenced containers. You can specify more than one container by repetitions of the --volumes-from argument. The container ID may be optionally suffixed with :ro or :rw to mount the volumes in read-only or read-write mode, respectively. By default, Docker mounts the volumes in the same mode (read write or read only) as the reference container.

Labeling systems like SELinux require placing proper labels on volume content mounted into a container. Without a label, the security system might prevent the processes running inside the container from using the content. By default, Docker does not change the labels set by the OS.

To change the label in the container context, you can add either of two suffixes :z or :Z to the volume mount. These suffixes tell Docker to relabel file objects on the shared volumes. The z option tells Docker that two containers share the volume content. As a result, Docker labels the content with a shared content label. Shared volume labels allow all containers to read/write content. The Z option tells Docker to label the content with a private unshared label. Only the current container can use a private volume.

Detached mode (-d, --detach)

The --detach (or -d ) flag starts a container as a background process that doesn't occupy your terminal window. By design, containers started in detached mode exit when the root process used to run the container exits, unless you also specify the --rm option. If you use -d with --rm , the container is removed when it exits or when the daemon exits, whichever happens first.

Don't pass a service x start command to a detached container. For example, this command attempts to start the nginx service.

This succeeds in starting the nginx service inside the container. However, it fails the detached container paradigm in that, the root process ( service nginx start ) returns and the detached container stops as designed. As a result, the nginx service starts but can't be used. Instead, to start a process such as the nginx web server do the following:

To do input/output with a detached container use network connections or shared volumes. These are required because the container is no longer listening to the command line where docker run was run.

Override the detach sequence (--detach-keys)

Use the --detach-keys option to override the Docker key sequence for detach. This is useful if the Docker default sequence conflicts with key sequence you use for other applications. There are two ways to define your own detach key sequence, as a per-container override or as a configuration property on your entire configuration.

To override the sequence for an individual container, use the --detach-keys="<sequence>" flag with the docker attach command. The format of the <sequence> is either a letter [a-Z], or the ctrl- combined with any of the following:

  • a-z (a single lowercase alpha character )
  • @ (at sign)
  • [ (left bracket)
  • \\ (two backward slashes)
  • _ (underscore)

These a , ctrl-a , X , or ctrl-\\ values are all examples of valid key sequences. To configure a different configuration default key sequence for all containers, see Configuration file section .

Add host device to container (--device)

It's often necessary to directly expose devices to a container. The --device option enables that. For example, adding a specific block storage device or loop device or audio device to an otherwise unprivileged container (without the --privileged flag) and have the application directly access it.

By default, the container is able to read , write and mknod these devices. This can be overridden using a third :rwm set of options to each --device flag. If the container is running in privileged mode, then Docker ignores the specified permissions.

Note The --device option cannot be safely used with ephemeral devices. You shouldn't add block devices that may be removed to untrusted containers with --device .

For Windows, the format of the string passed to the --device option is in the form of --device=<IdType>/<Id> . Beginning with Windows Server 2019 and Windows 10 October 2018 Update, Windows only supports an IdType of class and the Id as a device interface class GUID . Refer to the table defined in the Windows container docs for a list of container-supported device interface class GUIDs.

If you specify this option for a process-isolated Windows container, Docker makes all devices that implement the requested device interface class GUID available in the container. For example, the command below makes all COM ports on the host visible in the container.

Note The --device option is only supported on process-isolated Windows containers, and produces an error if the container isolation is hyperv .

CDI devices

Note This is experimental feature and as such doesn't represent a stable API.

Container Device Interface (CDI) is a standardized mechanism for container runtimes to create containers which are able to interact with third party devices.

With CDI, device configurations are defined using a JSON file. In addition to enabling the container to interact with the device node, it also lets you specify additional configuration for the device, such as kernel modules, host libraries, and environment variables.

You can reference a CDI device with the --device flag using the fully-qualified name of the device, as shown in the following example:

This starts an ubuntu container with access to the specified CDI device, vendor.com/class=device-name , assuming that:

  • A valid CDI specification (JSON file) for the requested device is available on the system running the daemon, in one of the configured CDI specification directories.
  • The CDI feature has been enabled on the daemon side, see Enable CDI devices .

Attach to STDIN/STDOUT/STDERR (-a, --attach)

The --attach (or -a ) flag tells docker run to bind to the container's STDIN , STDOUT or STDERR . This makes it possible to manipulate the output and input as needed. You can specify to which of the three standard streams ( STDIN , STDOUT , STDERR ) you'd like to connect instead, as in:

The following example pipes data into a container and prints the container's ID by attaching only to the container's STDIN .

The following example doesn't print anything to the console unless there's an error because output is only attached to the STDERR of the container. The container's logs still store what's written to STDERR and STDOUT .

The following example shows a way of using --attach to pipe a file into a container. The command prints the container's ID after the build completes and you can retrieve the build logs using docker logs . This is useful if you need to pipe a file or something else into a container and retrieve the container's ID once the container has finished running.

Note A process running as PID 1 inside a container is treated specially by Linux: it ignores any signal with the default action. So, the process doesn't terminate on SIGINT or SIGTERM unless it's coded to do so.

See also the docker cp command .

Keep STDIN open (-i, --interactive)

The --interactive (or -i ) flag keeps the container's STDIN open, and lets you send input to the container through standard input.

The -i flag is most often used together with the --tty flag to bind the I/O streams of the container to a pseudo terminal, creating an interactive terminal session for the container. See Allocate a pseudo-TTY for more examples.

Using the -i flag on its own allows for composition, such as piping input to containers:

Specify an init process

You can use the --init flag to indicate that an init process should be used as the PID 1 in the container. Specifying an init process ensures the usual responsibilities of an init system, such as reaping zombie processes, are performed inside the created container.

The default init process used is the first docker-init executable found in the system path of the Docker daemon process. This docker-init binary, included in the default installation, is backed by tini .

Allocate a pseudo-TTY (-t, --tty)

The --tty (or -t ) flag attaches a pseudo-TTY to the container, connecting your terminal to the I/O streams of the container. Allocating a pseudo-TTY to the container means that you get access to input and output feature that TTY devices provide.

For example, the following command runs the passwd command in a debian container, to set a new password for the root user.

If you run this command with only the -i flag (which lets you send text to STDIN of the container), the passwd prompt displays the password in plain text. However, if you try the same thing but also adding the -t flag, the password is hidden:

This is because passwd can suppress the output of characters to the terminal using the echo-off TTY feature.

You can use the -t flag without -i flag. This still allocates a pseudo-TTY to the container, but with no way of writing to STDIN . The only time this might be useful is if the output of the container requires a TTY environment.

Specify custom cgroups

Using the --cgroup-parent flag, you can pass a specific cgroup to run a container in. This allows you to create and manage cgroups on their own. You can define custom resources for those cgroups and put containers under a common parent group.

Using dynamically created devices (--device-cgroup-rule)

Docker assigns devices available to a container at creation time. The assigned devices are added to the cgroup.allow file and created into the container when it runs. This poses a problem when you need to add a new device to running container.

One solution is to add a more permissive rule to a container allowing it access to a wider range of devices. For example, supposing the container needs access to a character device with major 42 and any number of minor numbers (added as new devices appear), add the following rule:

Then, a user could ask udev to execute a script that would docker exec my-container mknod newDevX c 42 <minor> the required device when it is added.

Note : You still need to explicitly add initially present devices to the docker run / docker create command.

Access an NVIDIA GPU

The --gpus flag allows you to access NVIDIA GPU resources. First you need to install the nvidia-container-runtime .

Note You can also specify a GPU as a CDI device with the --device flag, see CDI devices .

Read Specify a container's resources for more information.

To use --gpus , specify which GPUs (or all) to use. If you provide no value, Docker uses all available GPUs. The example below exposes all available GPUs.

Use the device option to specify GPUs. The example below exposes a specific GPU.

The example below exposes the first and third GPUs.

Restart policies (--restart)

Use the --restart flag to specify a container's restart policy . A restart policy controls whether the Docker daemon restarts a container after exit. Docker supports the following restart policies:

This runs the redis container with a restart policy of always . If the container exits, Docker restarts it.

When a restart policy is active on a container, it shows as either Up or Restarting in docker ps . It can also be useful to use docker events to see the restart policy in effect.

An increasing delay (double the previous delay, starting at 100 milliseconds) is added before each restart to prevent flooding the server. This means the daemon waits for 100 ms, then 200 ms, 400, 800, 1600, and so on until either the on-failure limit, the maximum delay of 1 minute is hit, or when you docker stop or docker rm -f the container.

If a container is successfully restarted (the container is started and runs for at least 10 seconds), the delay is reset to its default value of 100 ms.

Specify a limit for restart attempts

You can specify the maximum amount of times Docker attempts to restart the container when using the on-failure policy. By default, Docker never stops attempting to restart the container.

The following example runs the redis container with a restart policy of on-failure and a maximum restart count of 10.

If the redis container exits with a non-zero exit status more than 10 times in a row, Docker stops trying to restart the container. Providing a maximum restart limit is only valid for the on-failure policy.

Inspect container restarts

The number of (attempted) restarts for a container can be obtained using the docker inspect command. For example, to get the number of restarts for container "my-container";

Or, to get the last time the container was (re)started;

Combining --restart (restart policy) with the --rm (clean up) flag results in an error. On container restart, attached clients are disconnected.

Clean up (--rm)

By default, a container's file system persists even after the container exits. This makes debugging a lot easier, since you can inspect the container's final state and you retain all your data.

If you are running short-term foreground processes, these container file systems can start to pile up. If you'd like Docker to automatically clean up the container and remove the file system when the container exits, use the --rm flag:

Note If you set the --rm flag, Docker also removes the anonymous volumes associated with the container when the container is removed. This is similar to running docker rm -v my-container . Only volumes that are specified without a name are removed. For example, when running the following command, volume /foo is removed, but not /bar : copying = false, 2000);"> $ docker run --rm -v /foo -v awesome:/bar busybox top Volumes inherited via --volumes-from are removed with the same logic: if the original volume was specified with a name it isn't removed.

Add entries to container hosts file (--add-host)

You can add other hosts into a container's /etc/hosts file by using one or more --add-host flags. This example adds a static address for a host named my-hostname :

You can wrap an IPv6 address in square brackets:

The --add-host flag supports a special host-gateway value that resolves to the internal IP address of the host. This is useful when you want containers to connect to services running on the host machine.

It's conventional to use host.docker.internal as the hostname referring to host-gateway . Docker Desktop automatically resolves this hostname, see Explore networking features .

The following example shows how the special host-gateway value works. The example runs an HTTP server that serves a file from host to container over the host.docker.internal hostname, which resolves to the host's internal IP.

The --add-host flag also accepts a : separator, for example:

Logging drivers (--log-driver)

The container can have a different logging driver than the Docker daemon. Use the --log-driver=<DRIVER> with the docker run command to configure the container's logging driver.

To learn about the supported logging drivers and how to use them, refer to Configure logging drivers .

To disable logging for a container, set the --log-driver flag to none :

Set ulimits in container (--ulimit)

Since setting ulimit settings in a container requires extra privileges not available in the default container, you can set these using the --ulimit flag. Specify --ulimit with a soft and hard limit in the format <type>=<soft limit>[:<hard limit>] . For example:

Note If you don't provide a hard limit value, Docker uses the soft limit value for both values. If you don't provide any values, they are inherited from the default ulimits set on the daemon.
Note The as option is deprecated. In other words, the following script is not supported: copying = false, 2000);"> $ docker run -it --ulimit as = 1024 fedora /bin/bash

Docker sends the values to the appropriate OS syscall and doesn't perform any byte conversion. Take this into account when setting the values.

For nproc usage

Be careful setting nproc with the ulimit flag as Linux uses nproc to set the maximum number of processes available to a user, not to a container. For example, start four containers with daemon user:

The 4th container fails and reports a "[8] System error: resource temporarily unavailable" error. This fails because the caller set nproc=3 resulting in the first three containers using up the three processes quota set for the daemon user.

Stop container with signal (--stop-signal)

The --stop-signal flag sends the system call signal to the container to exit. This signal can be a signal name in the format SIG<NAME> , for instance SIGKILL , or an unsigned number that matches a position in the kernel's syscall table, for instance 9 .

The default value is defined by STOPSIGNAL in the image, or SIGTERM if the image has no STOPSIGNAL defined.

Optional security options (--security-opt)

The --security-opt flag lets you override the default labeling scheme for a container. Specifying the level in the following command allows you to share the same content between containers.

Note Automatic translation of MLS labels isn't supported.

To disable the security labeling for a container entirely, you can use label=disable :

If you want a tighter security policy on the processes within a container, you can specify a custom type label. The following example runs a container that's only allowed to listen on Apache ports:

Note You would have to write policy defining a svirt_apache_t type.

To prevent your container processes from gaining additional privileges, you can use the following command:

This means that commands that raise privileges such as su or sudo no longer work. It also causes any seccomp filters to be applied later, after privileges have been dropped which may mean you can have a more restrictive set of filters. For more details, see the kernel documentation .

On Windows, you can use the --security-opt flag to specify the credentialspec option. The credentialspec must be in the format file://spec.txt or registry://keyname .

Stop container with timeout (--stop-timeout)

The --stop-timeout flag sets the number of seconds to wait for the container to stop after sending the pre-defined (see --stop-signal ) system call signal. If the container does not exit after the timeout elapses, it's forcibly killed with a SIGKILL signal.

If you set --stop-timeout to -1 , no timeout is applied, and the daemon waits indefinitely for the container to exit.

The Daemon determines the default, and is 10 seconds for Linux containers, and 30 seconds for Windows containers.

Specify isolation technology for container (--isolation)

This option is useful in situations where you are running Docker containers on Windows. The --isolation=<value> option sets a container's isolation technology. On Linux, the only supported is the default option which uses Linux namespaces. These two commands are equivalent on Linux:

On Windows, --isolation can take one of these values:

The default isolation on Windows server operating systems is process , and hyperv on Windows client operating systems, such as Windows 10. Process isolation has better performance, but requires that the image and host use the same kernel version.

On Windows server, assuming the default configuration, these commands are equivalent and result in process isolation:

If you have set the --exec-opt isolation=hyperv option on the Docker daemon , or are running against a Windows client-based daemon, these commands are equivalent and result in hyperv isolation:

Specify hard limits on memory available to containers (-m, --memory)

These parameters always set an upper limit on the memory available to the container. Linux sets this on the cgroup and applications in a container can query it at /sys/fs/cgroup/memory/memory.limit_in_bytes .

On Windows, this affects containers differently depending on what type of isolation you use.

With process isolation, Windows reports the full memory of the host system, not the limit to applications running inside the container

With hyperv isolation, Windows creates a utility VM that is big enough to hold the memory limit, plus the minimal OS needed to host the container. That size is reported as "Total Physical Memory."

Configure namespaced kernel parameters (sysctls) at runtime (--sysctl)

The --sysctl sets namespaced kernel parameters (sysctls) in the container. For example, to turn on IP forwarding in the containers network namespace, run this command:

Note Not all sysctls are namespaced. Docker does not support changing sysctls inside of a container that also modify the host system. As the kernel evolves we expect to see more sysctls become namespaced.

Currently supported sysctls

IPC Namespace:

  • kernel.msgmax , kernel.msgmnb , kernel.msgmni , kernel.sem , kernel.shmall , kernel.shmmax , kernel.shmmni , kernel.shm_rmid_forced .
  • Sysctls beginning with fs.mqueue.*
  • If you use the --ipc=host option these sysctls are not allowed.

Network Namespace:

  • Sysctls beginning with net.*
  • If you use the --network=host option using these sysctls are not allowed.

IMAGES

  1. How To Assign Multiple IP Addresses To Network Interface In Linux

    ip address assign linux

  2. How to Find IP Address in Linux [Step-by-Step]

    ip address assign linux

  3. How To Assign Multiple IP Addresses To Network Interface In Linux

    ip address assign linux

  4. How To Find Your Console IP Address On Linux

    ip address assign linux

  5. How to Assign IP Address in Linux

    ip address assign linux

  6. How to configure an IP range on Ubuntu 16/18

    ip address assign linux

VIDEO

  1. HOW TO ASSIGN IP ADDRESS ON MIKROTIK ROUTER INTERFACE

  2. How to assign Static IP Address in Ubuntu 17.04

  3. Ip Address Settings With Windows 11 For Internet Connection

  4. How To Configure Static IP in Ubuntu 18.04 Desktop

  5. SMC EX250 IP Address. Assign or Change Configuration

  6. configure ip address in linux method 2

COMMENTS

  1. How to Change IP Address in Linux

    Quick Tip How to Change IP Address in Linux Learn different ways of changing the IP address in Linux. Also learn how to make the changes [ermanent. Sep 20, 2022 — Team LHB How to Change IP Address in Linux 10 Sec Bitcoin ETFs Opened a Gateway for Capital: Michael Saylor As a sysadmin, you'll often deal with IP address configuration.

  2. How to Use the ip Command on Linux

    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.

  3. How to Assign an IP Address on a Linux Computer (with Pictures)

    Method 1 Debian, Ubuntu, & Linux Mint Download Article 1 Verify your Linux version. Popular Debian-based Linux distributions include Ubuntu, Mint, and Raspbian versions. 2 Open Terminal. This is the command line app that's the basis of all Linux distributions. Depending on your Linux version, you may have several ways of opening Terminal:

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

    Manual Network Configuration in Linux and How to Set a Static IP Address Last updated: January 22, 2024 Written by: Hiks Gerganov Administration Networking ip systemctl 1. Introduction Many Linux distributions come with a network manager. In theory, it should help during the networking setup.

  5. How To Change IP Address on Linux

    To change your IP address on Linux, use the "ifconfig" command followed by the name of your network interface and the new IP address to be changed on your computer. To assign the subnet mask, you can either add a "netmask" clause followed by the subnet mask or use the CIDR notation directly.

  6. 3 Ways to change ip address in Linux

    To change IP address in Linux, we can use "ifconfig" command. Type ifconfig followed by the name of your network interface and the new IP address. Press enter. The new ip address will be assigned to this interface. For example, ifconfig eth0 192.168..100 netmask 255.255.255. will change the ip address on eth0 to 192.168..100.

  7. Linux ip Command with Examples

    The ip command is a powerful tool for configuring network interfaces that any Linux system administrator should know. It is used to bring interfaces up or down, assign and remove addresses and routes, manage ARP cache, and much more.

  8. Linux Assign IP Address: Step-by-Step Guide to Assigning an IP Address

    The first step in assigning an IP address in Linux is to open a terminal window. This can be done by clicking on the terminal icon in your desktop environment or by using the keyboard shortcut Ctrl+Alt+T. The terminal window provides a command-line interface where you can enter the necessary commands to assign an IP address. 2.

  9. Linux ip Command Examples

    1. Find out which interfaces are configured on the system. 2. Query the status of a IP interface. 3. Configure the local loop-back, Ethernet and other IP interfaces. 4. Mark the interface as up or down. 5. Configure and modify default and static routing. 6. Set up tunnel over IP. 7. Show ARP or NDISC cache entry. 8.

  10. 16 Linux ip command examples to configure network interfaces

    1. Show IP Address of all the available interfaces using ip command 2. Show IP Address of individual interface 3. List interfaces based on interface type 4. Check if NIC's link state is enabled or disabled 5. Change NIC's Link state 6. Assign/Add IPv4 and IPv6 address 7. Un-Assign/Delete IPv4 and IPv6 address 8.

  11. How to Set Static IP Address and Configure Network in Linux

    Gateway: 192.168..1 DNS Server 1: 8.8.8.8 DNS Server 2 : 4.4.4.4 Configure Static IP Address in RHEL/CentOS/Fedora: To configure static IP address in RHEL / CentOS / Fedora, you will need to edit: /etc/sysconfig/network /etc/sysconfig/network-scripts/ifcfg-eth0 Where in the above "ifcfg-eth0" answers to your network interface eth0.

  12. How to Set a Static IP Address in Ubuntu

    Quick Links What Is a Static IP Address? Setting a Static IP in Ubuntu Set a Static IP in Ubuntu with the GUI Connection Convenience Key Takeaways After gathering your connection name, subnet mask, and default gateway, you can set a static IP address in the terminal using the nmcli command.

  13. How to Assign Static IP Address on Ubuntu Linux

    Method 1: Assign static IP in Ubuntu using command line Note for desktop users: Use static IP only when you need it. Automatic IP saves you a lot of headache in handling network configuration. Step 1: Get the name of network interface and the default gateway

  14. Set IP Address in Linux Using ip Command

    Syntax: ip addr add [ip_address/subnet_mask] dev [interface_name] Here's an example of how you might add the IP address 192.168.56.102 with a subnet mask of 255.255.255. (or /24 in CIDR notation) to the interface enp0s8: sudo ip addr add 192.168.56.102/24 dev enp0s8 This command doesn't give any output.

  15. How To Configure Static IP Address In Linux And Unix

    Table of Contents 1. Configure Static IP Address In Linux 1.1. Assign Static IP address In Fedora, RHEL, CentOS, AlmaLinux, Rocky Linux 1.1.1. Set Static IP Address By Editing Network Configuration File 1.1.2. Set IP Address Using Nmtui 1.1.3. Set IP Address Using Nmcli 1.2. Configure Static IP Address In Debian, Ubuntu 1.2.1.

  16. 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:

  17. How to Configure Static IP Address on Ubuntu 20.04

    Typically, in most network configurations, the IP address is assigned dynamically by the router DHCP server. Setting a static IP address may be required in different situations, such as configuring port forwarding or running a media server . Configuring Static IP address using DHCP

  18. How to configure IP address in Linux

    These methods are: - Changing the configuration file Using the nmcli command Using the nmtui utility Using the nn-connection-editor tool Let's discuss each method in detail. Changing IP addresses in configuration files Linux uses a configuration file for each interface to store its configuration.

  19. How to Set a Static IP Address in Linux

    How to Set a Static IP Address in Linux Unsupervised Learning Posts How to Set a Static IP Address in Linux How to Set a Static IP Address in Linux Set Your Static IP in Ubuntu Set Your Static IP in CentOS Using the ip Command ifconfig is being replaced by the ip command.

  20. How to assign static IP address on Ubuntu Linux

    To assign a static IP address on Ubuntu (server or client) through the Settings app, use these steps: Open Settings. Click on Network. Click the Settings button for the "Wired" network interface. Click the IPv4 tab. Select the Manual option for the "IPv4 Method" setting. Under the "Addresses" section, confirm the static IP address ...

  21. How To Assign Multiple IP Addresses To Network Interface In Linux

    2. Configure Multiple IP Addresses using nmcli Command. nmcli is a command-line tool for managing NetworkManager, which is commonly used for network configuration on Linux systems. To assign multiple IP addresses to a network interface using the nmcli command in Linux, you can follow these steps. 1. List Network Connections:

  22. How To Assign IP Address To Remote Linux Systems Via SSH

    To do so, run: $ ssh [email protected] 'nmcli con show' Replace the username and IP address with your own. Sample Output: NAME UUID TYPE DEVICE Wired connection 1 60e8eaf3-89f9-3e9f-9919-1944e7abee20 ethernet ens18 As you see in the output above, the network connection name is ' Wired connection 1 '.

  23. How to set a static internal IP in Ubuntu

    Note down the range of IP addresses you'll be able to use. Use the command ip addr to find out your machine's current IP address. This tutorial assumes that your network adapter is called enp0s3 ...

  24. What is SSH and how do you use it? The secure shell basics you ...

    Remembering all of those IP addresses and usernames can be a real headache for some. Fortunately, SSH makes it possible for you to create a configuration file that houses all of this information.

  25. How to configure a static IP address

    5. Fill in the IP address, Gateway, Network prefix length, and DNS fields.. 6. Tap Save in the upper right corner to apply your changes.. How to set a static IP address on Linux. The process for Linux is a little more involved. Bear in mind that while you could do it by running a ip adr command, that change would be reversed with every reboot. To set up the static IP permanently, follow these ...

  26. How to Find/Get your IP Address in Linux

    192.168../16. You can determine your system private IP address by querying the network stack with commands such as ip, ifconfig or hostname. In Linux, the standard tool for displaying and configuring network interfaces is ip . To display a list of all network interfaces and the associated IP address type the following command:

  27. 6 Linux commands to find Public IP addresses for your machine

    For Ipv4 public address: curl -4 ifconfig.me -w "\n" To get an Ipv6 public IP address: curl -6 ifconfig.me -w "\n" Note: "-w "\n" in the command is just to get the output in the next line, followed by the command prompt.If you want, you can use the command without it.

  28. How to install RHEL on the Marvell Octeon 10 DPU

    The DHCP server for the purposes of this document of installing RHEL will be used to give the UEFI bootloader an IP address when attempting to PXE boot the ISO image through TFTP. (Note: This DHCP server can also be used by U-Boot to burn the UEFI bootloader onto the secondary SPI memory device on the Marvell Octeon 10).

  29. docker run

    Add Linux capabilities--cap-drop: Drop Linux capabilities--cgroup-parent: ... To assign a static IP to containers, you must specify subnet block for the network. ... Once connected, the containers can communicate using only another container's IP address or name.