Tecmint: Linux Howtos, Tutorials & Guides

How to Set Static IP Address and Configure Network in Linux

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

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

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

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

Configure Static IP Address in RHEL/CentOS/Fedora:

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

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

Let’s start with the first file:

Open that file and set:

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

In that file make the following changes:

You will only need to edit the settings for:

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.

Support Us

We are thankful for your never ending support.

Related Posts

Check Word Count in Linux

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

Linux tee Command Examples

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

Linux Tee and Xargs Command Examples

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

sysctl Command Examples in Linux

How to Modify Linux Kernel Variables Using sysctl Command

Clear Linux Terminal Screen

4 Useful Commands to Clear Linux Terminal Screen

Extract tar.xz File in Linux

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

static ip linux 2022

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!

how to assign a static ip in linux

Written By Daniel Miessler

Recommended.

how to assign a static ip in linux

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,

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.

Configure static IP address on CentOS Linux

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:

The other lines are less important. If you're curious to know what are those, here you go.

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:

Edit Network Connection

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

Choose Edit Connection

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

Set IP Address Using Nmtui

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:

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.

Set Static IP Address In Debian

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:

Configure IP address in Ubuntu

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:

View IP Address

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.

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.

View IP Address In FreeBSD

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:

View IP Address In FreeBSD Using ifconfig 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:

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 .

' data-src=

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

' data-src=

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.

' data-src=

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…

' data-src=

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.

' data-src=

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 assign a static ip in linux

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

nmtui static IP

Select an interface to configure

nmtui-2 static IP

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

nmtui-3 static IP

Navigate to IPV4 and select ‘show’

nmtui-4 static IP config

Hit Okay. Go back and select Quit

nmtui-quit static IP

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.

' src=

About James

Related articles.

how to assign a static ip in linux

It's FOSS

How to Assign Static IP Address on Ubuntu Linux

Dimitrios

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

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

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

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

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

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

Method 1: Assign static IP in Ubuntu using command line

Static IP set up Ubuntu

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

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

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

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

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

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

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

Step 2: Locate Netplan configuration

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

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

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

You need to edit this file for using static IP.

Step 3: Edit Netplan configuration for assigning static IP

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

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

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

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

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

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

Save the file and apply the changes with this command:

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

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

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

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

Method 2: Switch to static IP address in Ubuntu graphically

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

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

Assign Static IP address in Ubuntu Linux

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

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

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

Assigning static IP in Ubuntu Linux

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

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

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

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

It's FOSS

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Your link has expired.

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

Success! Your billing info has been updated.

Your billing was not updated.

IT Support Blog

Office of information technology.

The College of Natural Sciences The University of Texas at Austin

IT Support Blog

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 .

how to assign a static ip in linux

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

linux category thumbnail

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:

linux category thumbnail

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?

' src=

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

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 *

Vultr SSD VPS

How to Configure Static IP Address on Linux System

Configure Static IP Address on Linux

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.

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.

Image titled Assign an IP Address on a Linux Computer Step 1

Image titled Assign an IP Address on a Linux Computer Step 3

Image titled Assign an IP Address on a Linux Computer Step 4

Image titled Assign an IP Address on a Linux Computer Step 5

Image titled Assign an IP Address on a Linux Computer Step 6

Image titled Assign an IP Address on a Linux Computer Step 7

Image titled Assign an IP Address on a Linux Computer Step 9

Image titled Assign an IP Address on a Linux Computer Step 15

Image titled Assign an IP Address on a Linux Computer Step 18

Image titled Assign an IP Address on a Linux Computer Step 19

Image titled Assign an IP Address on a Linux Computer Step 21

Expert Q&A

Video . by using this service, some information may be shared with youtube..

how to assign a static ip in linux

You Might Also Like

Set up a Network in Ubuntu

About This Article

Jack Lloyd

Reader Success Stories

Buddy HaDagi

Buddy HaDagi

Jan 27, 2017

Is this article up to date?

Dmitry Ugay

Dmitry Ugay

Oct 10, 2017

Am I a Narcissist or an Empath Quiz

Featured Articles

Play FIFA 23 Career Mode

Trending Articles

Talk to a Girl in a Group

Watch Articles

Make Homemade Soup

wikiHow Tech Help Pro:

Level up your tech skills and stay ahead of the curve

Linux.com

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

how to assign a static ip in linux

Hacking the Linux Kernel in Ada – Part 3

Hacking the linux kernel in ada – part 2, hacking the linux kernel in ada – part 1.

how to assign a static ip in linux

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

how to assign a static ip in linux

Support OLF and Possibly Win a Prize

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

how to assign a static ip in linux

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:

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:

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

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:

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:

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:

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 assign a static ip in linux

Sandra Henry-Stocker

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

How to configure a static IP address on Linux

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.

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.

how to assign a static ip in linux

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

Shubham's user avatar

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/

Matt's user avatar

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.

jasonlam604's user avatar

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:

image created with this Dockerfile

image build command:

container run command:

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)

cibercitizen1's user avatar

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.

user2105103's user avatar

& 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

Stuart Cardall's user avatar

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.

errordeveloper's user avatar

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

Phan Dolphy's user avatar

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.

sourcejedi's user avatar

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

Андрей Сердюк's user avatar

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 .

Hot Network Questions

how to assign a static ip in linux

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 .

GoLinuxCloud

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:

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]

In the above output, I have four interfaces:

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:

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]

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]

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

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]

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 the hostname in the space provided then press " OK "

Set Static IP in Rocky Linux [6 Different Methods]

You will receive a prompt that the hostname configuration has been successful.

Set Static IP in Rocky Linux [6 Different Methods]

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.

Buy GoLinuxCloud a Coffee

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.

cropped Screenshot 2020 03 15 at 23.04.41

Learn [Solve IT]

Hands-on on Windows, macOS, Linux, Azure, GCP, AWS

How to Configure A Static IP Address on Windows 11

renerdliam

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

how to assign a static ip in linux

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

how to assign a static ip in linux

Then, click Properties.

how to assign a static ip in linux

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 .

how to assign a static ip in linux

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

how to assign a static ip in linux

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.

guest

IMAGES

  1. How to assign static IP address in Linux|How to change Hostname in Linux > BENISNOUS

    how to assign a static ip in linux

  2. How to assign Static/Manul IP Address in Ubuntu 16.10/Linux Mint

    how to assign a static ip in linux

  3. How to Assign Static IP Address on Ubuntu 20.04 LTS

    how to assign a static ip in linux

  4. How to Assign Static IP Address on Ubuntu Linux

    how to assign a static ip in linux

  5. 🎉 Assigning static ip. How to Set Static IP Address and Configure Network in Linux. 2019-02-25

    how to assign a static ip in linux

  6. Can't access the My Cloud device

    how to assign a static ip in linux

VIDEO

  1. trixbox Part 3: Running trixbox server without a static IP

  2. HOW TO ASSIGN A STATIC IP ADDRESS IN WINDOWS 11

  3. Command to show IP of Linux Server ?

  4. Manjaro / Arch

  5. Axis Lab

  6. How to configure a DHCP server with static IP to a specific client

COMMENTS

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

    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:

  2. How to Set a Static IP Address in Linux

    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

  3. How to Set a Static IP Address in Ubuntu

    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.

  4. How to Configure Static IP Address on Ubuntu 20.04

    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.

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

    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.

  6. How to configure a static IP on Linux

    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

  7. Setting up static IP address for Linux: Easier than ...

    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.

  8. How to Assign Static IP Address on Ubuntu Linux

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

  9. How to Set a Static IP on a Linux Machine

    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

  10. How to assign a static IP address in Linux

    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.

  11. Is possible set an ip address static in a linux image developed in

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

  12. How to Configure Static IP Address on Linux System

    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.

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

    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.

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

  15. How to Use the ip Command on Linux

    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.

  16. How to configure a static IP address on RHEL 8 / CentOS 8 Linux

    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.

  17. How to configure a static IP address on Linux

    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.

  18. Netplan static IP on Ubuntu configuration

    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.

  19. How to configure static IP address on Alpine Linux

    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.

  20. linux

    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.

  21. Set Static IP in Rocky Linux [6 Different Methods]

    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:

  22. How to set up static IP address on Debian Linux 10/11

    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.

  23. How to Configure A Static IP Address on Windows 11

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