

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.
Tutorial Feedback...
If you appreciate what we do here on tecmint, you should consider:.
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.
Related Posts

6 Wc Command to Count Number of Lines, Words, and Characters in File

How to Use ‘tee’ Command in Linux [8 Useful Examples]

How to Run Commands from Standard Input Using Tee and Xargs in Linux

How to Modify Linux Kernel Variables Using sysctl Command

4 Useful Commands to Clear Linux Terminal Screen

How to List and Extract tar.xz File in Linux
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.
Got something to say? Join the discussion. Cancel reply
Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.
Save my name, email, and website in this browser for the next time I comment.
Don't subscribe All Replies to my comments Notify me of followup comments via e-mail. You can also subscribe without commenting.
Daniel Miessler
How to Set a Static IP Address in Linux
Created/Updated: February 2, 2022

- Set Your Static IP in Ubuntu
- Set Your Static IP in CentOS
- Using the ip Command
ifconfig is being replaced by the ip command.
Configuring a static IP can be difficult in Linux because it’s different based on the distro and version you’re using. This guide will show you how to configure a static IP address on the most popular Linux distros.
As of version 17 of Ubuntu, networking is configured using Netplan , which is a YAML-based configuration system. It allows you to set your IP, netmask, gateway, and DNS all in one place.
Start by editing the file for your interface: in this case 01-netcfg.yaml .
vi /etc/netplan/ 01-netcfg.yaml
Editing your interface file
You’ll either see networkd or systemd in the renderer spot; keep that the same.
network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: no addresses: [192.168.2.2/24] gateway4: 192.168.1.1 nameservers: addresses: [8.8.8.8,8.8.4.4]
To have your changes take effect, restart networking with this command:
You can then apply this configuration by running netplan apply .
YAML configs are crazy about indentation, so if you get an error check there first.
netplan apply
Now let’s do the same thing in CentOS. Here we’ll need to edit things the old way using sysconfig and network-scripts:
vi /etc/sysconfig/network-scripts/ ifcfg-eth0
You’ll change what you see there to something like this:
HWADDR=$SOMETHING TYPE= Ethernet BOOTPROTO= none // turns off DHCP IPADDR= 192.168.2.2 // set your IP PREFIX=24 // subnet mask GATEWAY= 192.168.2.254 DNS1=1.1.1.2 // set your own DNS DNS2=1.0.0.2 DNS3=9.9.9.9 DEFROUTE=yes IPV4_FAILURE_FATAL=no NAME=eth0 DEVICE=eth0 ONBOOT= yes // starts on boot
You can then apply this configuration by running:
/etc/init.d/ network restart
Ok, that will get you up and running with a static IP on the two most common Linux distros. Now let’s take a deeper look at the new ip command.
Using ip and netplan
Most Linux nerds have been using ipconfig for a long time, but it’s now being replaced with a new command called ip . Here’s how to do some basic tasks using the new command.
Show your IP using ip
ip addr show
or even shorter and more efficient…
(both commands show all interfaces)
Show only one interface using ip
ip a show eth0
Bring an interface up or down using ip
ip link set eth1 up
ip link set eth1 down
Only show IPv4 interfaces
Ok, so now you should know how to set a static IP on both Ubuntu and CentOS, as well as how to get some basic network information using ip instead of ipconfig .
Happy hacking!

Written By Daniel Miessler
Recommended.
- Information Security
- Recommended Tutorials
- A Vim Primer
- A Tcpdump Primer
- Security Assessment Types
- URLs vs. URIs
- Unsupervised Learning
- Book Summaries

- Open Source
- Free Ebooks And Videos
How To Configure Static IP Address In Linux And Unix
3 different ways to set static ip address in linux and freebsd.
Setting IP address after a fresh Linux installation is one of the mandatory skill that every Linux and Unix administrator should learn. We can easily assign IP address in Linux that has GUI mode. However, configuring IP networking from command line mode is entirely different! This step by step tutorial describes how to configure static IP address in Linux and Unix operating systems from command line mode.
The steps provided below are tested on AlmaLinux 8, CentOS 8 server editions, Ubuntu 22.04, 18.04, and 16.04 server and desktop editions and FreeBSD 13, FreeBSD 12 server editions. However, it should work on most RPM-based and DEB-based Linux systems and BSD flavors.
1. Configure Static IP Address In Linux
Setting up IP address in RPM-based and DEB-based systems is little bit different. First, we will see how to configure IP address on RPM-based systems.
1.1. Assign Static IP address In Fedora, RHEL, CentOS, AlmaLinux, Rocky Linux
Assigning IP address in Fedora and RHEL-based systems can be done with different ways. We can set IP address,
- by manually editing the network configuration file,
- using Nmcli command line tool,
- and using Nmtui text-based user interface tool.
1.1.1. Set Static IP Address By Editing Network Configuration File
In Fedora, RHEL and its clones like CentOS, AlmaLinux and Rocky Linux, the network interface card (shortly NIC ) configuration are stored under /etc/sysconfig/network-scripts/ directory.
Note: Here, I run all commands as root user. If you logged-in as normal user, just prepend each command with ' sudo ' .
First, let us find the name of the network card.
To do so, run:
Sample output:
Or, use this command to display detailed output:
Usually, the wired network card name will start with letter "e" , and wireless card name will start letter with "w" .
As you see in the above output, my wired network card name is enp0s3 . It might be different in your distribution, but it usually start with letter "e".
Let us now configure a static IP address to this NIC.
Open the network card config file in any editor:
Here, I use vi editor to edit the network config file. You can use any text/graphical editor of your choice, for example nano or gedit .
Set bootproto (boot protocol) to none and set the IP address, subnet mask, gateway, and DNS server as shown below.

This is how a typical network card configuration file looks like in any RPM based systems. Did you notice the lines that I have marked in bold (and arrows in the image)? Those are the important lines.
Let me explain about those lines:
- BOOTPROTO="none" - This line shows that the network card's IP address should be configured manually . If you set the value as "dhcp" , then the network card will accept the IP address from any DHCP server in the network.
- IPADDR0="192.168.225.150" - This line indicates the IP address of the network card. Here, the zero in the IPADDR 0 parameter indicates that this card as configured with only one IP address. If you want to set more than one IP address (i.e virtual IP address), then add new lines - for example IPADDR1, IPADDR2 and set different IP addresses of your choice.
- PREFIX0="24" - This line indicates the subnet mask, i.e 255.255.255.0. Here you can specify more than one subnet with lines PREFIX1, PREFIX 2 etc.
- GATEWAY0="192.168.225.1" - This is the gateway address of the NIC.
- DNS1="8.8.8.8" - The Name server address. You can also specify more than one DNS with lines DNS2, DNS3 etc.
The other lines are less important. If you're curious to know what are those, here you go.
- DEFROUTE - Whether to use this connection as the default route.
- HWADDR - Indicates the hardware address of the network device.
- IPV4_FAILURE_FATAL - Whether to disable the device if IPv4 configuration fails. The default value is no.
- IPV6INIT - Whether to enable IPv6 support for this connection.
- ONBOOT - Whether to start this connection at system boot.
- UUID - The UUID associated with this connection.
- TYPE - Indicates the type os this connection i.e. Ethernet, WiFi etc.
For more details about each parameter, check the manual page of ip addr command.
Once you setup all details, save and close the file. Restart the network service for the changes to take effect.
Or, simply reboot your system.
Now, verify the new static IP address using command:
Or, you can check a specific network card's address as shown below.
1.1.2. Set IP Address Using Nmtui
Alternatively, you can use the NetworkManager TUI (nmtui) utility to configure IP address.
If it is not installed already, you can install it using command:
Now, start nmtui utility by entering the following command:
Choose "Edit a connection" option:

Choose the network interface card to configure from the left pane and select "Edit" option on the right and hit ENTER key:

Enter the IP address, netmask, gateway, and DNS details etc. Finally, Click OK to save the changes.

Restart Networkmanager service:
Or reboot your system to take effect the changes.
1.1.3. Set IP Address Using Nmcli
nmcli is a command line NetworkManager interface to create, view, modify, activate, deactivate and remove network connections.
To show all active and inactive network connections, run:
As you see in the above output, it shows two connection profiles namely "System eth0" and "docker0" and the devices they are attache to.
Let us see how to configure IP address for the eth0 connection.
To assign a static IP address to eth0 interface using nmcli, run:
Here, we are setting IP address 192.168.1.20/24 to the connection profile "System eth0" with gateway 192.168.1.101 and DNS 8.8.8.8. Replace the the name of the connection profile with your own along with the IP address, gateway and DNS.
Update the changes using command:
That's it. We have assigned a static IP address to eth0 card.
Let us verify it using command:
You can also verify the IP address by displaying the contents of the ifcfg-eth0 config file.
Suggested read:
- How To Assign Multiple IP Addresses To Single Network Card In Linux
1.2. Configure Static IP Address In Debian, Ubuntu
Configuring IP address in Debian and Ubuntu using nmcli and nmtui tools is exactly same as described above. If you're using desktop environment in Debian or Ubuntu, nmcli and nmtui comes pre-installed.
Setting up static IP address by editing network configuration files is bit different in DEB-based systems. The following steps shows you how to configure static IP address in Debian 11 bullseye.
1.2.1. Set Static IP Address In Debian
Let us first list the available network interfaces using command:
As you see in the above output, my network interface card name is ens18 .
We can set static IP address by editing the network interface config file. All network configuration files are stored under /etc/network/ directory in Debian-based systems.
Edit /etc/network/interfaces/ file using any text editor:
Add or modify the following lines to configure static IP address.

Replace ens18 with your network interface name along with the IP address, gateway and dns. save the file and close it.
Restart NetworkManager service to update the changes.
That's it. You can now check the IP address using command:
1.2.2. Assign Static IP Address In Ubuntu
Like I already said, setting up IP address with nmcli or nmtui tools is exactly same as we explained in the RHEL-based systems section above.
If you want to set IP address by manually editing network configuration file, follow the steps provided below.
Edit /etc/network/interfaces/ file in any text editor:

Save and close the file.
Restart network service using command:
Or, simply reboot the system.
Now, check the new static IP address using any one of the following commands:

Heads Up: Starting from Ubuntu 17.10, we no longer use /etc/network/interfaces file to configure IP address. In recent Ubuntu versions, we use Netplan utility to configure IP address. To configure IP address on recent Ubuntu distributions, refer the following link.
- How To Configure IP Address In Ubuntu 18.04 LTS
We just learned how to configure static IP address in Linux from Command line. Let us now configure static IP address in Unix. For the purpose of this tutorial, I will be using FreeBSD 13 .
2. Configure Static IP Address In FreeBSD
We use " ifconfig " command to find out the network card name in FreeBSD. Here, I logged-in as root user to perform the following commands.

Here em0 is the network interface card name.
To configure static IP address, edit /etc/rc.conf file:
Add/modify the lines as shown below.
Restart network service using the following command:
Now, check if the IP address has been changed or not using command:

To configure network card to obtain IP address from a DHCP server, add or modify the following lines only:
Save and close the file. Restart networking service or reboot your system to take effect the changes.
Related read:
- How To Configure Static And Dynamic IP Address In Arch Linux
- How To Find Default Gateway IP Address In Linux And Unix From Commandline
- How To Find Out The Connected State Of A Network Cable In Linux
- vnStat – Monitor Network Bandwidth In Linux and BSD
- Display Network Information In Linux Using What IP Tool
In this tutorial, we learned a few ways to configure static IP address in Linux and Unix operating systems. In the first method, we assigned the IP address by manually editing network configuration files. In the second and third methods method, we used nmcli and nmtui to set IP address from command line in Linux.
Featured image by mohamed Hassan from Pixabay .

Senthilkumar Palani (aka SK) is the Founder and Editor in chief of OSTechNix. He is a Linux/Unix enthusiast and FOSS supporter. He lives in Tamilnadu, India.
How To Perform Arithmetic Operations In Bash
How to change user password in linux, you may also like, how to set or change hostname in debian..., vnstat – monitor network bandwidth in linux and..., prettyping – make the output of ping command..., connect and disconnect wifi from commandline in linux, geo – a simple bash utility to get..., install tp-link ac600 archer t2u nano wifi usb....

Thank you for this clearly written description of static IP configuration. I would be interested in a follow-up article that discusses static IP for a walk-about laptop. Specifically, I need STATIC_IP_A when I’m part of NETWORK_1, STATIC_IP_B when I’m part of NETWORK_2,…, STATIC_IP_Z when I’m part of NETWORK_N, and dynamic IP address the rest of the time.

I am afraid we couldn’t do that in Linux with single network interface card. However, It is possible to do it with manageable network switch. We could create different vlans and assign different set of IP addresses for each vlan.
Is there some way to: 1. detect which network is available 2. run one or more scripts that are per-network specific 3. the scripts would used DHCP or static-IP as needed 4. might need to connect-inspect-bounce-configure
While I would like to detect wired & wireless and launch appropriate scripts, wireless is by far the most common and most useful.
I am trying, with poor success, to find the network connection hooks that I could use to launch my own scripts.
ASIDE — I use Linux Mint 17.3 from the Ubuntu family of distributions.
As I understood.. Create a script..First detect which network available on system. And show available network status like up or down and also show Static ip or DHCP IP. Something like- Available—Status—DH/ ST——–IP eth0. Up. dhcp. ******* wlan0. Down. —- ——- Second option detect network configuration – Enter Available network name- when we enter name , then again show option set ip address dhcp or static- -> Input dhcp (auto set dhcp ip) -> Input static (Then auto set static ip) or Enter -> Ipaddress- -> netmask- -> gateway- -> dns1 -> dns2
I think when we are connected both network (wlan & lan) ..the first priority of wireless network if wireless network down then automatic up lan port…

Static IP setting for Linux Mint Sylvia worked perfectly…
… AFTER I substituted enp3s0 for enp0s3. Who knows why mine was different?
THANKS for accurate instructions which actually WORK! Rare in my world of Googling.

What ip adress re we supposed to enter in when configuring the static ip ?
Any IP address of your choice.
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 .
This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More

How to configure a static IP on Linux
By default, upon installation, any Linux system uses DHCP for its network configuration. This implies that it automatically obtains an IP address from a router or a DHCP server in a network. However, there are certain instances that require configuration of a static IP. A good example is where you have a server, e.g a web server or an FTP server. You definitely don’t want its IP to keep changing once the DHCP lease time is over. This will definitely cause loss of service once the IP changes.
Let’s see how we can configure a static IP in different distros.
Configuring a static IP in Fedora 27, CentOS and RHEL 7
Firstly, list the IP of all interfaces
Sample Output
Above, we can observe that our IP address is 192.168.43.160 and netmask is 255.255.255.0 We are going to configure this statically.
Navigate to the following path to view interface statistics of interface enp0s3
The sample output should contain the following parameters:
This tells the system to start networking service at boot time.
To set a static IP, modify the following settings:
Restart the networking service
Verify the settings.
Also, check the nameservers
using nmtui utility
nmtui, short for Network Manager Text User interface is a GUI tool that painlessly allows you to configure your network interface without having to touch the command line. It can be installed both on RPM and Debian based distributions.
For Centos & RHEL 7
Launching nmtui

Select an interface to configure

Press ‘Tab’ key to navigate to the other options. Hit edit.

Navigate to IPV4 and select ‘show’

Hit Okay. Go back and select Quit

Finally, restart networking service.
Configuring a static IP in Ubuntu 14.04, 16.04
Navigate to the network interface configuration file
DHCP settings
To configure a static IP, remove DHCP and append ‘static’ to ‘inet’ and enter your preferred address, netmask, gateway and dns-name servers
Restart networking
Verify the settings using ifconfig command and cat /etc/resolv.conf
Wrapping up
Your thoughts about this article are highly welcome. Feel free to get back to us for any clarifications.
About James
Related articles.
- How to fix the repository is not signed error on Ubuntu 20.04
- How to Create Additional FTP Accounts on VestaCP
- How to restrict SSH access only to specific IPs
- LAMP on CentOS 6

How to Assign Static IP Address on Ubuntu Linux
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

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.

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.

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.
Explained: Which Ubuntu Version Should I Use?
How to recover deleted files in linux [beginner's guide], reduce computer eye strain with this nifty tool in linux, how to run c/c++ programs in linux [terminal & eclipse], how to install windows 10 in virtualbox in linux, 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

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.
- Utility Menu
IT Support Blog
Office of information technology.
The College of Natural Sciences The University of Texas at Austin

How to Set a Static IP on a Linux Machine
Step-by-step guide.
Here’s a little primer on static Internet Protocol (IP) Addresses. Computers usually have the ability to grab a Dynamic Host Configuration Protocol (DHCP) address by default. Most networks are set to give out these dynamic IP addresses to any device that gets on the network and says, “I’m here! Give me an IP address so that I can use Google!”
The trouble with DHCP addresses is that they are dynamic. When a DHCP “lease” runs out, the computer or device may grab another available DHCP IP address. Normally this is ok and allows seamless Internet access to any computer; however, sometimes the need arises to statically assign an IP address for remote access, file transfers, or any other number of reasons.
To get a static IP address for your computer, submit a help ticket at http://cns.utexas.edu/help . Once you receive an IP assignment, follow the instructions below to get the IP Address and additional needed information onto your computer’s network connection.
NOTE: To make these changes, you must have an account with administrative rights on the machine. You will either need to login as root, or be able to use the "sudo" command on your machine. In the following, we assume you are logged in as root.
NOTE: Since the graphical interfaces change so much between Linux distributions, we're only going to show command line configuration here. While the command line interface does change between Linux distributions, it changes less than the graphical interfaces.
NOTE: We provide directions below for the most popular Linux distributions in CNS. If you use another distribution (like Gentoo, OpenSUSE, etc), you can contact the CNS Help Desk at http://cns.utexas.edu/help/ for additional instructions or help. There is also a tremendous amount of helpful information on the Internet on this topic. If the steps here do not work for you, Google for it. You'll almost certainly be able to find the procedure for the particular distribution of Linux you are running.
NOTE: Since part of the process described below is restarting the networking, you should always execute these commands from a local login to the machine, and not a remote sessions such as via ssh, vnc, etc.
How to add a static IP Address to a Linux computer
1) setting your system's hostname.
You should first set your system's hostname to the Fully Qualified Domain Name assigned to it. Assuming the assigned hostname for your machine is "pluto.cns.utexas.edu", you would use the following commands to set the hostname:
2) Edit your /etc/hosts file
Next, you should edit your /etc/hosts file to add a line containing your assigned IP address and FQDN. Assuming again your hostname is "pluto.cns.utexas.edu" and your IP address is 128.83.155.1, you can do this using the following command (all versions):
3) Setting the actual IP address
The first step is to figure out the name of your connected network interface. Run the command:
from the command prompt. It will output something like:
Now you need to set the IP address and additional information needed. The file and contents vary somewhat by Linux distribution. We assume the connected network interface name is em1 here – use whatever you determined to be your network name in the step above if it is different.
Debian and Ubuntu :
Edit the file /etc/network/interfaces and make the changes needed to specify your assigned IP address, Gateway, and Subnet Mask. The file should have comments in it to help you identify what needs to be done. Assuming again we are assigned 128.83.155.1 and pluto.cns.utexas.edu, and the network is a /24 network, then the file would read:
You would then restart the network interface using the commands:
Red Hat 7, CentOS 7, Scientific Linux 7, Fedora 22+:
These instructions are only for the newest versions of these operating system. See below for older versions.
On Red Hat based systems, each interface has its own configuration file /etc/sysconfig/networking-scripts/ifcfg- INTERFACE , where INTERFACE is the name of the interface. To configure em1, for example, you would edit the file /etc/sysconfig/networking-scripts/ifcfg-em1, and set it to something like the following:
Then you would restart the network interface using the commands:
On Arch Linux, the configuration file for network interface is /etc/netctl/ INTERFACE , where INTERFACE is the name of the interface. To configure em1 , for example, edit /etc/netctl/ em1 , and make it look like this:
Then start the network interface and enable the interface to start automatically at boot with the commands:
netctl restart em1 netctl enable em1
Red Hat, CentOS, Scientific Linux, Fedora
If you are not running one of the newer versions shown above, then you would edit the file /etc/sysconfig/networking-scripts/ifcfg-INTERFACE as follows:
Then restart the network interface using the command:
4) Configure your DNS servers if necessary
Related articles
How to Set a Static IP on a Windows Machine How to Set a Static IP on a Mac OS X Machine
Written by CNS OIT staff Questions or comments? The best and easiest way to contact us is via the CNS Help Desk form .
- April 2018 (2)
- March 2018 (4)
- February 2018 (4)
- January 2018 (3)
- December 2017 (3)
- November 2017 (4)
- October 2017 (7)
- September 2017 (4)
- August 2017 (4)
- July 2017 (5)
- June 2017 (5)
- May 2017 (7)
- April 2017 (4)
- March 2017 (4)
- February 2017 (4)
- January 2017 (3)
- December 2016 (3)
- November 2016 (4)
- October 2016 (5)
- September 2016 (4)
- August 2016 (5)
- July 2016 (4)
- June 2016 (4)
- May 2016 (5)
- April 2016 (4)
- March 2016 (5)
- February 2016 (5)
- January 2016 (1)
- December 2015 (2)
- November 2015 (5)
- October 2015 (4)
- September 2015 (4)
- August 2015 (5)
- July 2015 (4)
- June 2015 (5)
- May 2015 (4)
- April 2015 (6)
- March 2015 (2)
- Browser (5)
- Classroom (1)
- E-Mail (14)
- General (49)
- Hardware (3)
- Hosting (11)
- ISO Alerts (23)

Jesin's Blog
Welcome to the Portal of Technology
How to assign a static IP address in Linux
October 17, 2011 Linux Jesin A 2 Comments

This article explains assigning a static IP to your Linux machine through the command line. If you’re assigning a public IP address, you should’ve purchased it from your ISP. Assigning the IP address in Linux requires you to edit the network configuration file. The network interface files are located at different places according the Linux OS variant. This article will cover both Red Hat and Debian variants. You need to logged in as the root user to edit these files, or you should have sudo permissions.
Red Hat variants
Some of the Red Hat variant Linux OSes are CentOS, Fedora, SUSE Linux etc. If you’re using YUM to install packages then you have a Red Hat based OS. Use the VI editor and edit the following file
vi /etc/sysconfig/network-scripts/ifcfg-eth0
A machine having multiple Ethernet cards will have files named ifcfg-eth1, ifcfg-eth2 and so on. Add or edit the following lines
ONBOOT=yes BOOTPROTO=none IPADDR=192.168.0.2 NETMASK=255.255.255.0 GATEWAY=192.168.0.1
By default BOOTPROTO is set to dhcp which should be changed, setting ONBOOT to yes will activate this network adapter when Linux boots and the care should be taken when entering the NETMASK value. Because unlike Windows OSes which automatically assign Subnet masks based on the class of the IP address manual assigning is required in Linux. Even though the interface will work if classless NETMASK is entered, the system might have problems in communicating with other network devices as they have a classful subnet mask. Refer to the Wikipedia article on Classful network to check in which class your IP address lies.
Debian variants
If you use dpkg to install packages then you’re using a Debian based Linux OS. Using VI editor open the following file.
vi /etc/network/interfaces
If you’re using DHCP (which is the default) the following is shown
auto eth0 iface eth0 inet dhcp
To assign an IP address statically delete those lines and enter the following
iface eth0 inet static address 192.168.0.2 netmask 255.255.255.0 gateway 192.168.0.1
Here again you should keep an eye when entering the netmask.
Assigning the DNS IP addresses
Assigning DNS addresses is similar in both types of Linux OSes. Edit the following file using the VI editor
vi /etc/resolv.conf
The nameserver keyword is used to mention the DNS service IP address. If more than one DNS IP is to be specified use multiple entries
nameserver 8.8.8.8 nameserver 8.8.4.4
Restarting the interface and verifying the settings
For the changes to apply the interface has to be shutdown and brought up
ifdown eth0 ifup eth0 ifconfig
The ifconfig command should display the IP address and netmask assigned by you. Ping different IP addresses to check connectivity. To check the DNS ping a hostname or a domain name
ping google.com
You should get a reply.
Related posts:

October 18, 2011 at 3:54 am
I have a related question.
I have installed Ubuntu on several computers on a LAN. Somehow all of these computers have been assigned 192.168.x.x ip addresses, and these addresses do not collide.
I did *not* assign these static private subset ip addresses myself.
So I wonder how these are these static ip addresses in the private subnet determined? Does each Ubuntu computer simply scan, say by pinging, for others computers in the subnet. Here I am speculating!
That is, if a computer doesn’t get a response from 192.168.1.13, perhaps the computer assumes that there is no computer with that assigned ip adress???? That approach doesn’t seem rock solid as two computers could look for 192.168.1.13 at the same time and both claim that static ip address as their own when they don’t get a response.
Of course, I am just speculating! I actually do not know how Ubuntu assigns these static ip addresses in the private subnet, but I’d like to understand it better.
Any ideas how Ubuntu computes and assigns these static ip addresses in the private subnet?
October 18, 2011 at 1:05 pm
Hello Stefan, how did you check the IP address ? Using the ifconfig command ? Check out the following file /etc/network/interfaces If you find a line the line “iface eth0 inet dhcp” it means your computer has been configured to request IP address from a DHCP server. DHCP is a protocol which automatically assigns IP addresses to computers in the same physical segment.
I’ll explain briefly how DHCP works
- When you switch on your Ubuntu PC it sends a broadcast packet containing its MAC address requesting an IP address.
- This packet is received by all computers in the same physical segment including the DHCP server.
- The DHCP server responds by sending the IP address configuration to the computer which sent that broadcast packet.
This process is called DORA (Discover Offer Request Acknowledge)
Most broadband modems/routers are configured as DHCP servers, so if you have one of these in your network setup it would’ve assigned IP addresses for all your computers.
You can find out your DHCP server’s IP address by looking into the file /var/lib/dhcp/dhclient.leases
To learn more about DHCP read the Wikipedia article Dynamic Host Configuration Protocol
Leave a Reply Cancel reply
Your email address will not be published. Required fields are marked *
- Privacy Policy


How to Configure Static IP Address on Linux System

Configure Static IP on Linux
1. configure static ip address on ubuntu/debian linux, method 1: configure static ip via cli, method 2: configure a static ip by gui, 2. static ip address on fedora linux, method 1: configure a static ip by nmcli, method 2: configure a static ip address by cli, method 3: gui method of configuring a static ip, 3. static ip address on arch linux, method 1: configure static ip address by cli method, method 2: establish internet connection by gui method, extra tip: configure a router, final words, leave a reply cancel reply, latest post, kde plasma 5.27.2 released: what’s new, the open source firewall – ipfire 2.27 – core update 173 released: what’s new, xanmod linux kernel 6.2.1 released: what’s new, 15 best fractal software for linux, the 20 best vscode themes for programmers and developers, linux shell roundup: 15 most popular open source linux shells, 27 best linux tutorial books that you need to download now, everything you need to know about ubuntu dns servers, 10 best android emulators for linux, 10 best comic book viewers for linux, enhancing your linux experience: install linux kernel 6.2 in ubuntu and linux mint, 25 best free medical imaging software for linux, 15 best tools for linux font management, 20 best computer algebra systems for linux, stay connected, newsletter signup, editors' pick, 30 best game emulator consoles for linux, ultimate list of ethical hacking and penetration testing tools for kali linux, 10 best free office suites for linux | ms office alternative.
- EXPLORE Coupons Tech Help Pro Random Article About Us Quizzes Contribute Train Your Brain Game Improve Your English 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
- HELP US Support wikiHow Community Dashboard Write an Article Request a New Article More Ideas...
- EDIT Edit this Article
- PRO Courses New Tech Help Pro New Expert Videos About wikiHow Pro Coupons Quizzes Upgrade Sign In
- Browse Articles
- Quizzes New
- Train Your Brain New
- Improve Your English New
- Support wikiHow
- About wikiHow
- Easy Ways to Help
- Approve Questions
- Fix Spelling
- More Things to Try...
- H&M Coupons
- Hotwire Promo Codes
- StubHub Discount Codes
- Ashley Furniture Coupons
- Blue Nile Promo Codes
- NordVPN Coupons
- Samsung Promo Codes
- Chewy Promo Codes
- Ulta Coupons
- Vistaprint Promo Codes
- Shutterfly Promo Codes
- DoorDash Promo Codes
- Office Depot Coupons
- adidas Promo Codes
- Home Depot Coupons
- DSW Coupons
- Bed Bath and Beyond Coupons
- Lowe's Coupons
- Surfshark Coupons
- Nordstrom Coupons
- Walmart Promo Codes
- Dick's Sporting Goods Coupons
- Fanatics Coupons
- Edible Arrangements Coupons
- eBay Coupons
- 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 690,225 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.

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

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

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

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

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

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

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

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

- 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

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

Expert Q&A
Video . by using this service, some information may be shared with youtube..
- 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. ⧼thumbs_response⧽ Helpful 0 Not Helpful 0

- Don't forget to switch back to the regular (non-root) user account when you're done. ⧼thumbs_response⧽ Helpful 1 Not Helpful 1
You Might Also Like

- ↑ https://danielmiessler.com/study/set_ip/
- ↑ https://www.youtube.com/watch?v=oQd5eG9BZXE&t=
About This Article

- Send fan mail to authors
Reader Success Stories

Buddy HaDagi
Jan 27, 2017
Is this article up to date?

Dmitry Ugay
Oct 10, 2017

Featured Articles

Trending Articles

Watch Articles

- 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
- Embedded/IoT
- Open Source
- System Administration
- Certification
- What is Linux?

- Training and Tutorials
Setting Static IP address in Linux
To assign a static IP address, just open the terminal and type the following sudo ifconfig eth0 your_ip_adddress
Here eth0 is the name of your NIC(Network Interface Card). You need super user privileges to do static IP assignment. Its recommended that the IP you assign is in the range 10.xx.xx.xx or in the range 192.168.xx.xx.
RELATED ARTICLES MORE FROM AUTHOR

Hacking the Linux Kernel in Ada – Part 3
Hacking the linux kernel in ada – part 2, hacking the linux kernel in ada – part 1.

Looking to Hire or be Hired? Participate in the 10th Annual Open Source Jobs Report and Tell Us What Matters Most

Support OLF and Possibly Win a Prize
- Buying Guides
Complete Guides by How-To Geek
Our latest product roundups, reader favorites, more from how-to geek, latest geek news, latest reviews, across lifesavvy media.
Join 425,000 subscribers and get a daily digest of news, geek trivia, and our feature articles.
By submitting your email, you agree to the Terms of Use and Privacy Policy .
How to Use the ip Command on Linux
Dave McKay first used computers when punched paper tape was in vogue, and he has been programming ever since. After over 30 years in the IT industry, he is now a full-time technology journalist. During his career, he has worked as a freelance programmer, manager of an international software development team, an IT services project manager, and, most recently, as a Data Protection Officer. His writing has been published by howtogeek.com, cloudsavvyit.com, itenterpriser.com, and opensource.com. Dave is a Linux evangelist and open source advocate. Read more...

You can configure IP addresses, network interfaces, and routing rules on the fly with the Linux ip command. We’ll show you how you can use this modern replacement of the classic (and now deprecated) ifconfig .
How the ip Command Works
With the ip command, you can adjust the way a Linux computer handles IP addresses, network interfaces controllers (NICs), and routing rules . The changes also take immediate effect—you don’t have to reboot. The ip command can do a lot more than this, but we’ll focus on the most common uses in this article.
The ip command has many subcommands, each of which works on a type of object, such as IP addresses and routes. There are, in turn, many options for each of these objects. It’s this richness of functionality that gives the ip command the granularity you need to perform what can be delicate tasks. This isn’t ax work—it calls for a set of scalpels.
We’ll look at the following objects:
- Address : IP addresses and ranges.
- Link : Network interfaces, such as wired connections and Wi-Fi adapters.
- Route : The rules that manage the routing of traffic sent to addresses via interfaces ( links ).
Using ip with Addresses
Obviously, you first have to know the settings you’re dealing with. To discover which IP addresses your computer has, you use the ip command with the object address . The default action is show , which lists the IP addresses. You can also omit show and abbreviate address as “addr” or even “a.”
The following commands are all equivalent:
We see two IP addresses, along with a lot of other information. IP addresses are associated with network interface controllers (NICs). The ip command tries to be helpful and provides a bunch of information about the interface, too.
The first IP address is the (internal) loopback address used to communicate within the computer. The second is the actual (external) IP address the computer has on the local area network (LAN).
Let’s break down all the information we received:
- lo : The network interface name as a string.
- <LOOPBACK,UP,LOWER_UP>: This is a loopback interface. It’s UP , meaning it’s operational. The physical networking layer (layer one) is also up.
- mtu 65536: The maximum transfer unit. This is the size of the largest chunk of data this interface can transmit.
- qdisc noqueue: A qdisc is a queuing mechanism. It schedules the transmission of packets. There are different queuing techniques called disciplines. The noqueue discipline means “send instantly, don’t queue.” This is the default qdisc discipline for virtual devices, such as the loopback address.
- state UNKNOWN: This can be DOWN (the network interface is not operational), UNKNOWN (the network interface is operational but nothing is connected), or UP (the network is operational and there is a connection).
- group default: Interfaces can be grouped logically. The default is to place them all in a group called “default.”
- qlen 1000: The maximum length of the transmission queue.
- link/loopback: The media access control (MAC) address of the interface.
- inet 127.0.0.1/8: The IP version 4 address. The part of the address after the forward-slash ( / ) is Classless Inter-Domain Routing notation (CIDR) representing the subnet mask. It indicates how many leading contiguous bits are set to one in the subnet mask. The value of eight means eight bits. Eight bits set to one represents 255 in binary, so the subnet mask is 255.0.0.0.
- scope host: The IP address scope. This IP address is only valid inside the computer (the “host”).
- lo: The interface with which this IP address is associated.
- valid_lft: Valid lifetime. For an IP version 4 IP address allocated by Dynamic Host Configuration Protocol (DHCP), this is the length of time the IP address is considered valid and able to make and accept connection requests.
- preferred_lft: Preferred lifetime. For an IP version 4 IP address allocated by DHCP, this is the amount of time the IP address can be used with no restrictions. This should never be larger than the valid_lft value.
- inet6 : The IP version 6 address, scope , valid_lft , and preferred_lft .
The physical interface is more interesting, as we’ll show below:
- enp0s3: The network interface name as a string. The “en” stands for ethernet, “p0” is the bus number of the ethernet card, and “s3” is the slot number.
- <BROADCAST,MULTICAST,UP,LOWER_UP>: This interface supports broad- and multicasting , and the interface is UP (operational and connected). The hardware layer of the network (layer one) is also UP .
- mtu 1500: The maximum transfer unit this interface supports.
- qdisc fq_codel: The scheduler is using a discipline called “Fair Queuing, Controlled Delay.” It’s designed to provide a fair share of the bandwidth to all the traffic flows that use the queue.
- state UP: The interface is operational and connected.
- group default: This interface is in the “default” interface group.
- qlen 1000: The maximum length of the transmission queue.
- link/ether: The MAC address of the interface.
- inet 192.168.4.26/24: The IP version 4 address. The “/24” tells us there are 24 contiguous leading bits set to one in the subnet mask. That’s three groups of eight bits. An eight-bit binary number equates to 255; therefore, the subnet mask is 255.255.255.0.
- brd 192.168.4.255: The broadcast address for this subnet.
- scope global: The IP address is valid everywhere on this network.
- dynamic: The IP address is lost when the interface goes down.
- noprefixroute: Do not create a route in the route table when this IP address is added. Someone has to add a route manually if he wants to use one with this IP address. Likewise, if this IP address is deleted, don’t look for a route to delete.
- enp0s3: The interface with which this IP address is associated.
- valid_lft: Valid lifetime. The time the IP address will be considered valid; 86,240 seconds is 23 hours and 57 minutes.
- preferred_lft: Preferred lifetime. The time the IP address will operate without any restrictions.
- inet6: The IP version 6 address, scope , valid_lft , and preferred_lft .
Display Only IPv4 or IPv6 Addresses
If you want to limit the output to the IP version 4 addresses, you can use the -4 option, as follows:
If you want to limit the output to the IP version 6 addresses, you can use the -6 option, as follows:
Display Information for a Single Interface
If you want to see the IP address information for a single interface, you can use the show and dev options, and name the interface, as shown below:
You can also use the -4 or -6 flag to further refine the output so you only see that in which you’re interested.
If you want to see the IP version 4 information related to the addresses on interface enp0s3 , type the following command:
Adding an IP Address
You can use the add and dev options to add an IP address to an interface. You just have to tell the ip command which IP address to add, and to which interface to add it.
We’re going to add the IP address 192.168.4.44 to the enp0s3 interface. We also have to provide the CIDR notation for the subnet mask.
We type the following:
We type the following to take another look at the IP version 4 IP addresses on this interface:
The new IP address is present on this network interface. We jump on another computer and use the following command to see if we can ping the new IP address :
The IP address responds and sends back acknowledgments to the pings. Our new IP address is up and running after one simple ip command.
Deleting an IP Address
To delete an IP address, the command is almost the same as the one to add one, except you replace add with del , as shown below:
If we type the following to check, we see the new IP address has been deleted:
Using ip with Network Interfaces
You use the link object to inspect and work with network interfaces. Type the following command to see the interfaces installed on your computer:
To see a single network interface, just add its name to the command, as shown below:
Starting and Stopping Links
You can use the set option with either up or down to stop or start a network interface option. You also have to use sudo , as shown below:
We type the following to take a look at the network interface:
The state of the network interface is DOWN . We can use the up option to restart a network interface, as shown below:
We type the following to do another quick check on the state of the network interface:
The network interface was restarted, and the state is shown as UP .
Using ip with Routes
With the route object, you can inspect and manipulate routes. Routes define to where network traffic to different IP addresses is forwarded, and through which network interface.
If the destination computer or device shares a network with the sending computer, the sending computer can forward the packet directly to it.
However, if the destination device is not directly connected, the sending computer forwards the packet to the default router. The router then decides where to send the packet.
To see the routes defined on your computer, type the following command:
Let’s take a look at the info we received:
- default: The default rule. This route is used if none of the other rules match what’s being sent.
- via 192.168.4.1: Routes the packets via the device at 192.168.4.1. This is the IP address of the default router on this network.
- dev enp0s3: Use this network interface to send the packets to the router.
- proto dhcp: The routing protocol identifier. DHCP means the routes will be determined dynamically.
- metric 100: An indication of the preference of the route compared to others. Routes with lower metrics are preferentially used over those with higher metrics. You can use this to give preference to a wired network interface over a Wi-Fi one.
The second route governs traffic to the IP range of 169.254.0.0/16. This is a zero-configuration network , which means it tries to self-configure for intranet communication. However, you can’t use it to send packets outside the immediate network.
The principle behind zero-configuration networks is they don’t rely on DHCP and other services being present and active. They only need to see TCP/IP in order to self-identify to each of the other devices on the network.
Let’s take a look:
- 169.254.0.0/16: The range of IP addresses this routing rule governs. If the computer communicates on this IP range, this rule cuts in.
- dev enp0s3: The network interface the traffic governed by this route will use.
- scope link : The scope is link , which means the scope is limited to the network to which this computer is directly connected.
- metric 1000 : This is a high metric and isn’t a preferred route.
The third route governs traffic to the IP address range of 192.168.4.0/24. This is the IP address range of the local network to which this computer is connected. It’s for communication across, but within, that network.
Let’s break it down:
- 192.168.4.1/24: The range of IP addresses this routing rule governs. If the computer communicates within this IP range, this rule triggers and controls the packet routing.
- dev enp0s3: The interface through which this route will send packets.
- proto kernel: The route created by the kernel during auto-configuration.
- scope link: The scope is link , which means the scope is limited to the immediate network to which this computer is connected.
- src 192.168.4.26: The IP address from which packets sent by this route originate.
- metric 100: This low metric indicates a preferred route.
Display Information for a Single Route
If you want to focus on the details of a particular route, you can add the list option and IP address range of the route to the command as follows:
Adding a Route
We just added a new network interface card to this computer. We type the following and see it’s showing up as enp0s8 :
We’ll add a new route to the computer to use this new interface. First, we type the following to associate an IP address with the interface:
A default route using the existing IP address is added to the new interface. We use the delete option, as shown below, to delete the route and provide its details:
We’ll now use the add option to add our new route. The new interface will handle network traffic in the 192.168.121.0/24 IP address range. We’ll give it a metric of 100; because it will be the only route handling this traffic, the metric is pretty much academic.
Now, we type the following to see what it gives us:
Our new route is now in place. However, we still have the 192.168.4.0/24 route that points to interface enp0s8 —we type the following to remove it:
We should now have a new route that points all traffic destined for IP range 192.168.121.0/24 through interface enp0s8 . It should also be the only route that uses our new interface.
We type the following to confirm:
Taken Route, Not Taken Root
The great thing about these commands is they’re not permanent. If you want to clear them, just reboot your system. This means you can experiment with them until they work the way you want. And it’s a very good thing if you make a terrible mess of your system—a simple reboot will restore order.
On the other hand, if you want the changes to be permanent, you have to do some more work. Exactly what varies depending on the distribution family, but they all involve changing config files.
This way, though, you can test-drive commands before you make anything permanent.
RELATED: Best Linux Laptops for Developers and Enthusiasts
- › How to Set the Default Gateway in Linux
- › How to Use the arping Command on Linux
- › How to Calculate Subnet Masks on Linux With ipcalc
- › How to Set a Static IP Address in Ubuntu
- › 10 Basic Linux Commands for Beginners
- › Alienware Has New Gaming Keyboards, Mice, Monitors, and More
- › The Best PS5 Accessories of 2023
- › We Let ChatGPT Create AI Art, Here’s What It Made
- United States
- United Kingdom

By Sandra Henry-Stocker , Unix Dweeb, Network World |
How to configure a static IP address on Linux
When you need a linux system to have a static ip address rather than one that is set dynamically by dhcp, all that's required is some configuration changes and a restart. follow these steps to make the switch..

IP addresses on Linux systems are often assigned automatically by Dynamic Host Configuration Protocol (DHCP) servers. These are referred to as "dynamic addresses" and may change any time the system is rebooted. When a system is a server or will be remotely administered, however, it is generally more convenient for these systems to have static addresses, providing stable and consistent connections with users and applications.
Fortunately, the steps required to change a Linux system's IP address from dynamic to static are fairly easy, though they will be a little different depending on the distribution you are using. In this post, we'll look at how this task is managed on both Red Hat (RHEL) and Ubuntu systems.
There's no simple command that you can run to determine whether the IP address on a Linux system is assigned by DHCP or static. If it changes when the system restarts, it's clearly dynamically assigned, but even a dynamic address has some resistance to change. The best way is to look at the configuration file. More on this in the sections below.
To configure a static IP address on a Red Hat system, let's start by listing NetworkManager's connection. The nmcli command shown below will list network connections and devices on the system. Note that the device names and the connection names are not the same.
To change the network interface from dynamic to static, you need to edit the file in the /etc/sysconfig/network-scripts directory that represents the public interface. In this example, it's called ifcfg-Comtrend7BF9 (ifcfg- followed by the name of the connection). The boot protocol "BOOTPROTO=dhcp" line needs to be changed to "BOOTPROTO=static". In addition, the IP address to be used has to be added to the file. The end result will look something like this (NOTE: Don't add the "arrows" inserted below to highlight the lines you need to focus on):
Run the command systemctl restart NetworkManager after the changes have been made to make the changes effective.
Ubuntu 18.10
The nmcli (network manager command line interface) command can be used to list the network interfaces on an Ubuntu system. In the output below, we see both a loopback and a public network interface listed. The device on your system may have a different name. This one that reflects the location of the hardware.
To examine the network interface configuration settings on an Ubuntu system, you would use a command like this:
You can see from the last line in this output that the eth0 interface is currently assigned by DHCP. To change the setting to dynamic, you would change "dhcp" to "static" and add some other lines as well. For example, in the file as shown below, we have changed dhcp to static and specified the IP address we want to use along with other settings:
Restart the networking service or reboot the system to make the changes effective.
Changing network settings should be done only when the changes will not affect current connections and you can back out the changes if needed. It's always a good idea to make a copy of any configuration file before you make changes. Giving your backup copy a predictable name such as interfaces.prev , interfaces.orig or interfaces- will make it a little easier to identify.
- 9 career-boosting Wi-Fi certifications
- What is MPLS, and why isn't it dead yet?
- 11 ways to list and sort files on Linux
- 5 free network-vulnerability scanners
- How-to measure enterprise Wi-Fi speeds
Sandra Henry-Stocker has been administering Unix systems for more than 30 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She lives in the mountains in Virginia where, when not working with or writing about Unix, she's chasing the bears away from her bird feeders.
Copyright © 2019 IDG Communications, Inc.
- Stack Overflow Public questions & answers
- Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Talent Build your employer brand
- Advertising Reach developers & technologists worldwide
- About the company
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
How can I set a static IP address in a Docker container?
I'm perfectly happy with the IP range that docker is giving me by default 176.17.x.x , so I don't need to create a new bridge, I just want to give my containers a static address within that range so I can point client browsers to it directly. I tried using
from a Dockerfile, and it properly populated the interfaces file, but the interface itself didn't change. In fact, running ifup eth0 within the container gets this error:
RTNETLINK answers: Operation not permitted Failed to bring up eth0
- You could try using the --net=host option. The container will then be available on the host's IP address. – Mark O'Connor Aug 27, 2014 at 14:50
- Thanks Mark. I re-wrote the Dockerfile to set an interface called docker0 (which is what --net=host will create) with my static IP, built the image and loaded it using --net=host. But docker0 still gets its IP from DHCP and ifup docker0 still doesn't work. – dlanced Aug 27, 2014 at 15:33
- 1 Possible duplicate of Assign static IP to Docker container – Matt Dec 13, 2017 at 9:55
11 Answers 11
I have already answered this here https://stackoverflow.com/a/35359185/4094678 but I see now that this question is actually older then the aforementioned one, so I'll copy the answer as well:
Easy with Docker version 1.10.1, build 9e83765.
First you need to create you own docker network (mynet123)
than simply run the image (I'll take ubuntu as example)
then in ubuntu shell
Additionally you could use --hostname to specify a hostname --add-host to add more entries to /etc/hosts
Docs (and why you need to create a network) at https://docs.docker.com/engine/reference/commandline/network_create/

I'm using the method written here from the official Docker documentation and I have confirmed it works:
Using this approach I run my containers always with net=none and set IP addresses with an external script.
- Just trying this suggestion, but I've run into a problem: setting --net=none seems to make it impossible to --link containers. Is this correct? – Kryten Jan 29, 2015 at 23:24
- Sorry, I never used the --link commands (because my containers don't talk each other) – unlink Jan 30, 2015 at 7:42
- No prob. After I posted the comment, I thought about it more and it makes sense that it wouldn't work. But it also makes sense that you can configure multiple containers to communicate with one another by the method you've shown. This seems to be the approach of pipework (which I am now attempting to use) – Kryten Jan 30, 2015 at 17:45
- I got Object "netns" is unknown, try "ip help". – Michael Z Dec 22, 2016 at 13:07
Actually, despite my initial failure, @MarkO'Connor's answer was correct. I created a new interface (docker0) in my host /etc/network/interfaces file, ran sudo ifup docker0 on the host, and then ran
which picked up the static IP and assigned it to docker0 in the container.
This worked for me:
--cap-add=NET_ADMIN have rights for administering the net (i.e. for the /sbin/ip command)
myimages/image1 image for the container
/bin/sh -c "/sbin/ip addr add 172.17.0.8 dev eth0 ; bash" Inside the container run ip addr add 172.17.0.8 dev eth0 to add a new ip address 172.17.0.8 to this container (caution: do use a free ip address now and in the future ). Then run bash, just to not have the container automatically stopped.
My target scene: setup a distributed app with containers playing different roles in the dist-app. A "conductor container" is able to run docker commands by itself (inside) so to start and stop containers as needed. Each container is configured to know where to connect to access a particular role/container in the dist-app (so the set of ip's for each role must be known by each partner).
To do this:
- "conductor container"
image created with this Dockerfile
image build command:
container run command:
- Run containers with different roles.
First (not absolutely necessary) add entries to /etc/hosts to locate partners by ip or name (option --add-host )
Second (obviously required) assign a ip to the running container (use /sbin/ip in it)
Docker containers by default do not have sufficient privileges to manipulate the network stack. You can try adding --cap-add=NET_ADMIN to the run command to allow this specific capability. Or you can try --privileged=true (grants all rights) for testing.
Another option is to use pipework from the host.
- Setup your own bridge (e.g br0 )
- Start docker with: -b=br0
& with pipework ( 192.168.1.1 below being the default gateway ip address):
Edit: do not start with --net=none : this closes container ports.
See further notes
I understood that you are not looking at multi-host networking of containers at this stage, but I believe you are likely to need it soon. Weave would allow you to first define multiple container networks on one host, and then potentially move some containers to another host without loosing the static IP you have assigned to it.
- Explain static IP with Weave? Can't find it in the docs (not that that would be an excuse not to explain the answer properly). – sourcejedi Jan 15, 2016 at 14:34
- 1 You can start a container with -e WEAVE_CIDR=ip:192.168.1.2/24 , and given you have Weave Net running along with proxy environment setup in your shell ( weave launch; eval $(weave env) ), that container should get the IP address you have specified. – errordeveloper Jan 18, 2016 at 14:05
pipework also great, but If you can use hostname other than ip then you can try this script
You just need to run this command everytime you boot up your docker labs You can find my scripts with additional function here dockerip
For completeness: there's another method suggested on the Docker forums. (Edit: and mentioned in passing by the answer from Андрей Сердюк).
Add the static IP address on the host system, then publish ports to that ip, e.g. docker run -p 192.0.2.1:80:80 -d mywebserver .
Of course that syntax won't work for IPv6 and the documentation doesn't mention that...
It sounds wrong to me: the usual wildcard binds (*:80) on the host theoretically conflict with the container. In practice the Docker port takes precedence and doesn't conflict, because of how it's implemented using iptables. But your public container IP will still respond on all the non -conflicting ports, e.g. ssh.

I discovered that --net=host might not always be the best option, as it might allow users to shut down the host from the container! In any case, it turns out that the reason I couldn't properly do it from inside was because network configuration was designed to be restricted to sessions that begun with the --privileged=true argument.
You can set up SkyDns with service discovery tool - https://github.com/crosbymichael/skydock
Or: Simply create network interface and publish docker container ports in it like here https://gist.github.com/andreyserdjuk/bd92b5beba2719054dfe
Your Answer
Sign up or log in, post as a guest.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service , privacy policy and cookie policy
Not the answer you're looking for? Browse other questions tagged linux networking docker or ask your own question .
- The Overflow Blog
- How Intuit democratizes AI development across teams through reusability sponsored post
- The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie...
- Featured on Meta
- We've added a "Necessary cookies only" option to the cookie consent popup
- The [amazon] tag is being burninated
- Launching the CI/CD and R Collectives and community editing features for...
- Staging Ground Beta 1 Recap, and Reviewers needed for Beta 2
- Temporary policy: ChatGPT is banned
Hot Network Questions
- How to prove that the supernatural or paranormal doesn't exist?
- Finite abelian groups with fewer automorphisms than a subgroup
- Can I tell police to wait and call a lawyer when served with a search warrant?
- Resistance against timing attacks of AES candidates
- Recovering from a blunder I made while emailing a professor
- What sort of strategies would a medieval military use against a fantasy giant?
- Why is this sentence from The Great Gatsby grammatical?
- Replacing broken pins/legs on a DIP IC package
- How to make graphons pictures?
- How to react to a student’s panic attack in an oral exam?
- Checking system vs. SEPA and the like
- Atheists who follow the teachings of Jesus
- Lots of pick movement
- Why are physically impossible and logically impossible concepts considered separate in terms of probability?
- A limit involving the quotient of two sums
- Does Counterspell prevent from any further spells being cast on a given turn?
- Do roots of these polynomials approach the negative of the Euler-Mascheroni constant?
- What is the correct way to screw wall and ceiling drywalls?
- If you order a special airline meal (e.g. vegan) just to try it, does this inconvenience the caterers and staff?
- 2000s era show about a group of friends who used a remote to open a portal anytime they needed to escape from aliens or creatures
- Stats update during Index rebuild
- Should I use the mean or median of my data for queueing models?
- Chord III is rarely used, but Pachelbel's Canon in D has F#m
- Knocking Out Zombies
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .

Set Static IP in Rocky Linux [6 Different Methods]
Table of Contents
Different methods to set Static IP Address - Rocky Linux 8
After a successful installation of Rocky Linux on your environment , there is need to configure network. You can either configure a static or a dynamic IP address. Network connections in Rocky Linux are managed by NetworkManager daemon.
In this guide, we shall discuss how to configure IP addresses on Rocky Linux using the different methods available.
There are many ways to configure IP addresses on Rocky Linux. In this guide, we shall cover the following:
- Configuring IP address through manually editing the network interface file.
- Configure IP address using ifconfig utility
- Using ip utility
- Using ifcfg utility
- Configuring IP using the NMTUI tool
- Configuring IP address using NMCLI tool
Method-1: Manually Edit Network Interface Config File
The first method that we shall discuss is where you edit a configuration file for a specific network interface to set the IP address and other options such as the DNS server.
To do this, you first need to identify the available network interfaces. Run the command below to identify the available interfaces.
![Set Static IP in Rocky Linux [6 Different Methods] Set Static IP in Rocky Linux [6 Different Methods]](https://www.golinuxcloud.com/wp-content/uploads/rocky-15.jpg)
In the above output, I have four interfaces:
- Loopback interface (lo)
This information is important as you need to know the interface name, and most importantly the MAC address of the interface that you intend to configure.
It is also important to get the status of the NetworkManager service:
The network interface configuration files exist at /etc/sysconfig/network-scripts/ . The interface configuration files have the prefix ifcfg-<interfacce>
You can list the contents of the directory to identify the interface configuration files under /etc/sysconfig/network-scripts/ as shown:
Assuming we want to update or add or modify the IP address of the interface enp0s3 , we shall edit the file ifcfg-enp0s3 .
In the above configuration file, the following are the most important fields to take note of:
- TYPE - The interface type, such as Ethernet
- BOOTPROTO - This is the IP configuration method(Static/DHCP). Use "static" for a static IP or "dhcp" for a DHCP configuration.
- ONBOOT - allows the interface to come up when the machine reboots
- HWADDR - The MAC address of the interface
- DEFROUTE - specify if the interface will be used for the default route.
- NAME - The name of the interface, such as enp0s3
- DEVICE - The physical NIC name (obtained from "ip addr" command)
- IPADDR - The IP address that you intend to assign the interface
- PREFIX - The Subnet mask prefix, such as 24, 27, etc.
- GATEWAY - the gateway for the IP address assigned
- DNS - The DNS IP for the DNS server
Manually update these fields in the respective interface configuration file and save the changes. To activate the configuration, run the command below:
Method-2: Configure Static IP Address using ifconfig
You can also configure a static IP address on Rocky Linux using the ifconfig tool.
The syntax to configure IP Address using ifconfig tool would be:
For example to assign static IP address to enp0s8 interface, execute the following command:
Next in case this interface is the default interface, you would also need to provide the default gateway. To assign a default gateway to your interface, execute the following command:
In the above command, we have set the IP for the interface enp0s8 and also created a default route to pass through the same interface.
Method-3: Configure Static IP using ip command
We can also configure IP using the ip command provided by the iproute2 package. To get the general information of your network configuration on Rocky Linux, use the command below:
You can assign a static IP to an interface using following syntax:
For example to assign static IP to ens0p8 interface, we use following command:
Check the interface details after applying the above command:
You can then bring down and then bring up the interface to activate the changes:
To add the gateway:
Method-4: Configure Static IP using ifcfg Utility
Configure a static IP on Rocky Linux 8 using the ifcfg utility as shown below:
The above command adds the IP 172.29.10.10/24 to the interface enp0s8.
You can remove the IP address on the interface by the command below:
Use the following command to check the default routes:
Method-5: Set Static IP Address using NMTUI
NMTUI is the acronym of Network Manager Terminal User Interface . This means that you can manage the network using an interface presented through the terminal. To use this tool, you need to have some packages installed.
To edit a network connection, run the command below as root user or with sudo privilege:
You will see a screen like this below:
![Set Static IP in Rocky Linux [6 Different Methods] Set Static IP in Rocky Linux [6 Different Methods]](https://www.golinuxcloud.com/wp-content/uploads/setup-ip-on-rocky-e1629272517520.png)
Select the " Edit a connection " option to edit a network interface. You will then need to choose the interface that you wish to edit in the subsequent screen.
![Set Static IP in Rocky Linux [6 Different Methods] Set Static IP in Rocky Linux [6 Different Methods]](https://www.golinuxcloud.com/wp-content/uploads/setup-ip-on-rocky-1-e1629272538322.png)
Under IPv4 Configuration , hit the Enter key to bring the drop down menu and select Manual . Here, you are required to configure the IP configuration of the interface as desired.
![Set Static IP in Rocky Linux [6 Different Methods] Set Static IP in Rocky Linux [6 Different Methods]](https://www.golinuxcloud.com/wp-content/uploads/setup-IP-on-rocky-3-e1629272565948.png)
Set the IPv4 configuration to either Automatic or Manual if you want DHCP or Static IP configuration respectively.
Put the IP address at the " Addresses " section, remember to append the subnet mask of the IP. Such as 192.168.100.149/24 where /24 is the subnet mask prefix.
Add the Gateway for the IP and the DNS servers.
To have the interface always connected (after reboot), check the " Automatically connect " option. It is also advisable to check the " Available to all users " option unless you have a reason not to.
Finish the configuration by pressing " OK " at the bottom. Head back to the first screen to activate the connection.
![Set Static IP in Rocky Linux [6 Different Methods] Set Static IP in Rocky Linux [6 Different Methods]](https://www.golinuxcloud.com/wp-content/uploads/setup-ip-on-rocky-6-e1629272589993.png)
Choose the " Activate a connection " option to activate the specific interface that we have configured in the previous step.
Choose the interface then select the " Activate " button on the right.
![Set Static IP in Rocky Linux [6 Different Methods] Set Static IP in Rocky Linux [6 Different Methods]](https://www.golinuxcloud.com/wp-content/uploads/activate-a-connection-e1629272608566.png)
You can now exit and verify that the interface has come up.
You can also use nmtui to set the system hostname.
To achieve this, run the nmtui command once more and select the set system hostname option.
![Set Static IP in Rocky Linux [6 Different Methods] Set Static IP in Rocky Linux [6 Different Methods]](https://www.golinuxcloud.com/wp-content/uploads/configure-hostname-e1629272626266.png)
Set the hostname in the space provided then press " OK "
![Set Static IP in Rocky Linux [6 Different Methods] Set Static IP in Rocky Linux [6 Different Methods]](https://www.golinuxcloud.com/wp-content/uploads/setup-ip-on-rocky-5-e1629272641371.png)
You will receive a prompt that the hostname configuration has been successful.
![Set Static IP in Rocky Linux [6 Different Methods] Set Static IP in Rocky Linux [6 Different Methods]](https://www.golinuxcloud.com/wp-content/uploads/hostname-set-e1629272659223.png)
Verify the hostname by running the command below:
Method-6: Set Static IP Address using NMCLI on Rocky Linux
NMCLI is an acronym for Network Manager Command Line Interface . Just like NMTUI, NMCLI is a command-line NetworkManager configuration tool.
This tool can also be used to configure the network interfaces just like the two methods we have discussed above.
To configure the interfaces, we first of all need to check and see the available configurations.
You can also use the nmcli device show command to see a more detailed picture of your network configuration.
To configure manual network configuration for an interface using NMCLI, follow the interface below:
The above command sets the IP 172.29.10.10/24 to the interface enp0s8 .
You can also add the Gateway and DNS settings as below:
Finally, set the IP for the interface to manual:
You can also use the nmcli shell to edit interface configuration for a specific interface.
You will be presented with an interface such as this below:
You can run commands such as describe interface and also add the IP configuration from this shell.
Save the configuration for the settings to take effect.
Verify the IP configuration
In this tutorial we covered different methods to configure static IP Address in Rocky Linux using different tools and commands. The network configuration done using ip, ifcfg and ifconfig tool are non-persistent which means the changes are temporary and are valid only for the current session. If someone restarts the network service then your changes will be overwritten. Or if someone reboots the server then also the changes will be overwritten with the default configuration.
So if you are looking to set static IP address persistently across reboot then you should choose nmcli, nmtui or manually updating the network configuration file.
Further Reading
Rocky Linux Network Configuration
Didn't find what you were looking for? Perform a quick search across GoLinuxCloud
If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

For any other feedbacks or questions you can either use the comments section or contact me form.
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.

Learn [Solve IT]
Hands-on on Windows, macOS, Linux, Azure, GCP, AWS
How to Configure A Static IP Address on Windows 11
If you prefer a static IP address for your Windows 11 Computer, instead of the ones associated with your Modem or DNS server. You can easily configure your Windows 11 computer IP address to a static one.
This guide shows you how to do so. Earlier in the News: Emotet Variant now steals credit card data from Google Chrome .
First, launch the Windows 11 Start Menu and select “Settings”.

Next, click on the “Network and Internet” option.

Then, click Properties.

Next, scroll down to IP Settings and click Edit. You may also be interested in : How to set up sites and spaces on Confluence Cloud .

Click on the drop-down menu to change the IP settings from Automatic to Manual.

Next, switch on the IPv4 option and fill in your IP address and other details. If you don’t know your IP address, you may check out this guide on how to see your IP address in Windows 11.
Once you are done filling in the information. You should click on the Save button to save your settings.
I hope you find this guide helpful. Kindly leave a comment if you have any questions.
Thank you for reading this post. Kindly share it with others.

IMAGES
VIDEO
COMMENTS
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. 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:
Bring an interface up or down using ip ip link set eth1 up ip link set eth1 down Only show IPv4 interfaces ip -4 a Ok, so now you should know how to set a static IP on both Ubuntu and CentOS, as well as how to get some basic network information using ip instead of ipconfig. Happy hacking! Written By Daniel Miessler
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.
To assign a static IP address to ens3 interface, edit the file as follows: Set DHCP to dhcp4: no. Specify the static IP address. Under addresses: you can add one or more IPv4 or IPv6 IP addresses that will be assigned to the network interface. Specify the gateway. Under nameservers, set the IP addresses of the nameservers.
To assign a static IP address to eth0 interface using nmcli, run: $ sudo nmcli connection modify "System eth0" ip4 192.168.1.20/24 gw4 192.168.1.101 ipv4.dns 8.8.8.8 Here, we are setting IP address 192.168.1.20/24 to the connection profile "System eth0" with gateway 192.168.1.101 and DNS 8.8.8.8.
Select an interface to configure Press 'Tab' key to navigate to the other options. Hit edit. Navigate to IPV4 and select 'show' Hit Okay. Go back and select Quit Finally, restart networking service. Configuring a static IP in Ubuntu 14.04, 16.04 Navigate to the network interface configuration file nano /etc/sysconfig/interfaces DHCP settings
To edit it, you can use any editor or use this command: $ sudo nano /etc/network/interfaces Now, change or update the configuration to: auto eth0 iface eth0 inet static address 192.168.1.1 netmask 255.255.255. gateway 192.168..1 dns-nameservers 4.4.4.4 Next, save and close the file and restart the system for the changes to take place.
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
How to add a static IP Address to a Linux computer 1) Setting your system's hostname You should first set your system's hostname to the Fully Qualified Domain Name assigned to it. Assuming the assigned hostname for your machine is "pluto.cns.utexas.edu", you would use the following commands to set the hostname: 2) Edit your /etc/hosts file
To assign an IP address statically delete those lines and enter the following iface eth0 inet static address 192.168..2 netmask 255.255.255. gateway 192.168..1 Here again you should keep an eye when entering the netmask. Assigning the DNS IP addresses Assigning DNS addresses is similar in both types of Linux OSes.
1 Answer. To automatically set a static IP in the built image, using systemd-networkd: meta-custom |_ recipes-core |_ systemd |_ systemd_%.bbappend |_ files |_ <iface>.link |_ <iface>.network. For <iface> you have to set the interface to be configured by systemd-networkd, for example eth0, wlan0, ...
Method 1: Configure a Static IP by NMCLI On Fedora Linux, you can establish a network connection using a static IP with the command-line based network manager. The NMCLI settings are stored inside the /etc/NetworkManager/system-connections/ directory of your Linux filesystem.
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. 3 Switch to root.
To assign a static IP address, just open the terminal and type the following sudo ifconfig eth0 your_ip_adddress Here eth0 is the name of your NIC (Network Interface Card). You need super user privileges to do static IP assignment. Its recommended that the IP you assign is in the range 10.xx.xx.xx or in the range 192.168.xx.xx.
Deleting an IP Address. To delete an IP address, the command is almost the same as the one to add one, except you replace add with del, as shown below: sudo ip addr del 192.168.4.44/24 dev enp0s3. If we type the following to check, we see the new IP address has been deleted: ip -4 addr show dev enp0s3.
In this tutorial we learn how to set a static IP address for a network interface in RHEL 8 / CentOS 8. We show three methods to perform said action: by manually editing a connection file, by using the nmcli command line utility, and finally by using nmtui, a text-user interface.
To configure a static IP address on a Red Hat system, let's start by listing NetworkManager's connection. The nmcli command shown below will list network connections and devices on the system.
Click on top right network icon and select settings corresponding to the network interface you wish to assign with the static IP address. Select wired or Wifi network settings Next, click on the gear box icon next to your network connection you wish to configure. This could be wired or wireless connection. Select IPv4 from the top menu.
Configuring Static IP address on Alpine server We define DHCP or static configuration in /etc/network/interfaces file. The first entry must be a loopback (lo0) interface. For example, we can use the cat command: cat /etc/network/interfaces auto lo iface lo inet loopback My Ethernet device name is eth0.
Add the static IP address on the host system, then publish ports to that ip, e.g. docker run -p 192.0.2.1:80:80 -d mywebserver. Of course that syntax won't work for IPv6 and the documentation doesn't mention that... It sounds wrong to me: the usual wildcard binds (*:80) on the host theoretically conflict with the container.
Method-4: Configure Static IP using ifcfg Utility. Configure a static IP on Rocky Linux 8 using the ifcfg utility as shown below: [[email protected] ~]# ifcfg enp0s8 add 172.29.10.10/24. The above command adds the IP 172.29.10.10/24 to the interface enp0s8. You can remove the IP address on the interface by the command below:
How to static IP address on Debian Linux. The procedure is as follows to set up and configure a static IP information: Open the terminal application.
First, launch the Windows 11 Start Menu and select "Settings". Next, click on the "Network and Internet" option. Then, click Properties. Next, scroll down to IP Settings and click Edit. You may also be interested in: How to set up sites and spaces on Confluence Cloud. Click on the drop-down menu to change the IP settings from Automatic ...