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 set ip address linux

Written By Daniel Miessler

Recommended.

how to set ip address linux

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 692,381 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 set ip address 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?

Buddy HaDagi

Dmitry Ugay

Oct 10, 2017

Am I a Narcissist or an Empath Quiz

Featured Articles

Get Wrinkles Out of Polyester

Trending Articles

How to Fold a Gum Wrapper Heart in 9 Simple Steps

Watch Articles

Make Tabasco Sauce

wikiHow Tech Help Pro:

Level up your tech skills and stay ahead of the curve

How to configure IP address in Linux

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

Setting a temporary IP address

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

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

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

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

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

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

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

The following image shows the above exercise.

ip addr command

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

Linux ip address Command Usages and Examples

Setting a permanent IP address

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

Let's discuss each method in detail.

Changing IP addresses in configuration files

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

network configuration file

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

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

changing configuration files

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

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

restart interface to update the ip address

Using the nmcli command to configure IP addresses

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

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

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

Understanding Linux Network Manager Fundamental

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

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

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

Now, check the IP address again.

using nmcli command to configure ip address

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

The nmcli command on Linux Examples and Usages

Using the nmtui utility to update IP addresses

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

nmtui command

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

edit a connection

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

select nic

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

automatic ip dhcp option

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

dhcp option

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

show option

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

set ip adddress

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

confirm change

Select the Quit option and press the Enter key.

quit nmtui

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

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

verifing ip address update

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

The nmtui Command and Utility on Linux

Using the nm-connection-editor graphical utility

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

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

nm-connection-editor

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

edit a connection

Restart the interface and verify the new IP configuration.

verify update

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

The nm-connection-editor command on Linux

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

By ComputerNetworkingNotes Updated on 2022-11-02 07:25:54 IST

ComputerNetworkingNotes Linux Tutorials How to configure IP address in Linux

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

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 Change Your IP Address From the Command Line in Linux

Taylor Gibb is a professional software developer with nearly a decade of experience. He served as Microsoft Regional Director in South Africa for two years and has received multiple Microsoft MVP (Most Valued Professional) awards. He currently works in R&D at Derivco International. Read more...

Lowell is the founder and CEO of How-To Geek. He’s been running the show since creating the site back in 2006. Over the last decade, Lowell has personally written more than 1000 articles which have been viewed by over 250 million people. Prior to starting How-To Geek, Lowell spent 15 years working in IT doing consulting, cybersecurity, database management, and programming work. Read more...

how to set ip address linux

This trick should work on all Debian-based Linux distros, including Ubuntu. To get started, type ifconfig at the terminal prompt, and then hit Enter. This command lists all network interfaces on the system, so take note of the name of the interface for which you want to change the IP address.

To change the settings, you also use the ifconfig command, this time with a few additional parameters. The following command changes the network interface named “eth0” to use the IP address 102.168.0.1, and assigns the subnet mask 255.255.255.0:

You could, of course, substitute in whatever values you want. If you run ifconfig again, you will see that your interface has now taken on the new settings you assigned to it.

If you also need to change the Default Gateway used by the network interface, you can use the route command. The following command, for example, sets the default gateway for the “eth0” interface to 192.168.0.253:

To see your new setting, you will need to display the routing table. Type the following command at the prompt, and then hit Enter:

RELATED: How to Work with the Network from the Linux Terminal: 11 Commands You Need to Know

That’s all there is to changing your IP address from the terminal. If you’re interested in other great networking tools you can use at the terminal, be sure to check out our guide to the subject.

RELATED: Best Linux Laptops for Developers and Enthusiasts

how to set ip address linux

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

Create Systemd Service in Linux

How to Create a Systemd Service in Linux

mknod Command Examples

How to Create Device Files in Linux Using mknod Command

how to set ip address linux

Pydf – An Alternative “df” Command to Check Disk Usage in Different Colours

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

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.

howtouselinux

3 ways to change ip address in linux.

Do you need to change your IP address frequently? Are you having trouble finding a way to do it on Linux? If so, you have come to the right place. In this blog post, we will discuss three different ways that you can change your IP address on Linux.

We will also provide instructions on how to do it. So, whether you are a beginner or an expert Linux user, you should be able to follow along without any problems!

understanding network interface and ip address in Linux

Network interfaces are devices that allow communication with other devices on a computer network. A computer can have multiple network interfaces, each of which has its own IP address.

In Linux, you can view a list of all the network interfaces and their associated IP addresses by running the ifconfig -a or ip addr command. Check this post to get more info about how to find ip address in Linux .

change ip address with ifconfig Command in Linux

To change IP address in Linux, we can use “ifconfig” command. Type ifconfig followed by the name of your network interface and the new IP address. Press enter. The new ip address will be assigned to this interface.

For example, ifconfig eth0 192.168.0.100 netmask 255.255.255.0 will change the ip address on eth0 to 192.168.0.100.

The “interface” parameter specifies the name of the network interface. The “ip address” parameter specifies the IP address for the network interface. The “netmask” parameter specifies the netmask for the network interface.

The changes made with ifconfig will not persist after a reboot, which means that every time the system is restarted. The IP address will be reset to the value it had before.

In addition, ifconfig command is considered as deprecated command and it is replaced by iproute2 package in many distributions. 

procedure to change IP address with ifconfig command in Linux

The procedure to change IP address in Linux is as follows:

change ip address with ip Command in Linux

Another way to change your IP address on Linux is to use the ip command. This is a more advanced method to change your IP address. You will need to open a terminal window and type in the following command:

sudo ip addr add 192.168.0.100 255.255.255.0 dev eth0

Replace 192.168.0.100 with the IP address and netmask that you want to use.  This will add an IP address to your system. You can then close the terminal window and continue using your computer as normal.

This command adds the new IP address to the specified interface.

Note: It does not remove or update the existing IP address. It appends the current IP configuration.You need to run sudo ip addr del command to remove the old ip address.

The new settings take effect immediately – however they are not persistent and will be lost after a reboot.

 Ip command is more up-to-date, and it is considered as the standard tool for managing the network on Linux systems.

change ip address permanently in configuration file in Linux

You can change the IP Address permanently by modifying the configuration file. Under the /etc/sysconfig/network-scripts directory, you’ll see file for every network interface on your system. For example, if your interface is “eth0″, you’ll see ifcfg-eth0 file under this directory.

Modify the ifcfg-eth0 file with your favorite text editor (a lot of people prefer to use vi or nano) and change the IPADDR field accordingly as shown below to change the ip-address.

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

Change the IP address to the correct IP, make sure that the Netmask and Gateway are configured correctly as well and save.

#  vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" BOOTPROTO=none ONBOOT=yes TYPE="Ethernet" IPADDR="192.168.0.100" NETMASK="255.255.255.0" GATEWAY="192.168.0.1"

After you save the ifcfg-eth0 file you will have to restart the network. You can restart the network with the following command: systemctl restart network

Change Public ip address with VPN in Linux

A VPN (Virtual Private Network) is the best and safest way to change your public IP address. While there are many VPN apps on the market, one of the most popular options is ExpressVPN .

It can stop your ISP monitoring your internet activity. Changing to an address that’s based in another country can also give you access to that country’s streaming content.

We have found ExpressVPN to be extremely reliable and secure. Technically speaking, a VPN “hides” your IP address by creating an encrypted connection. This type of connection acts as a tunnel between your device and the internet.

So if you want to change your public IP address, look no further than ExpressVPN . Plus, they have a  30-day money-back guarantee  and  3 months free , so you can try them out risk-free.

Check out ExpressVPN here

FAQ about ip address in Linux

How to find your IP address in Linux

To find your IP address in Linux , use the ip addr command. This will print the IP address and other information about your network interfaces.

If you want to find out your public IP address, you can use the curl command. This will send a request to a web server and return your public IP address. curl ifconfig.me

What is the netmask for your ip address in Linux?

The netmask in Linux is a bitmask that determines what IP addresses are on the same network as your computer. If two computers have the same netmask, they are on the same network. If they have different netmasks, they are on different networks.

how to find the gateway for ip address in Linux

To find the gateway in Linux , you can use the route command. This will print the IP address of the gateway for your default route. You can also use the ip addr command to find the gateway.

what is difference between a private and public IP address in Linux

The private IP address space is reserved for internal networks only and cannot be routed on the Internet as addressing like a public IP address space can be, which makes it much more difficult to use this form of addressing on the Internet.

A public IP address can be easily found by looking up the domain name of a website. Conversely, a private IP address is much harder to find as it requires special software and tools to do so.

Additionally, most home users will not have a static public IP address but their private IP addresses will remain the same unless they take specific action to change it.

ifconfig command vs ip command

The ip command is a replacement for the ifconfig command. In earlier versions of Linux, the ifconfig command was the default utility for checking and verifying IP configuration. The ifconfig command does not support many modern features that were not relevant in earlier times.

The ifconfig command is deprecated. Although some Linux distributions still include the ifconfig command for backward compatibility in their current version of Linux, they may consider gradually removing it from their upcoming Linux versions.

Because of this, even if the ifconfig command is still available on some Linux distributions, you should use the ip command for all IP validation and verification-related tasks. The ip command is designed to meet the requirements of modern networks.

Welcome to howtouselinux.com !

Our website is dedicated to providing comprehensive information on using Linux.

We hope you find our site helpful and informative, and we welcome your feedback and suggestions for future content.

3 ways to get AWS S3 bucket size

When it comes to Amazon Web Services (AWS), S3 is one of the most popular services. This is because S3 provides a secure and scalable

How to get AWS Instance ID

If you’re running a business on Amazon Web Services (AWS), then you know that instances are an important part of your infrastructure. It’s crucial to

Understanding /etc/resolv.conf file in Linux

The /etc/resolv.conf file is a configuration file used by the Linux operating system to store information about Domain Name System (DNS) servers. This file contains

How to list repository in Linux

In Linux, a repository is a collection of software packages that are available for installation on your system. Think of it as an app store

How to Find Your IP Address in Ubuntu Linux

If you’re having trouble connecting to the internet or other devices on the network, checking your IP address can help you determine if the issue

2 ways to use Linux ip addr command

As a Linux user, you may have used the ip addr command at some point. But do you know what this command does and how

3 ways to fix ping: cannot resolve Unknown host

“ping: cannot resolve Unknown host” is an error message that typically appears when the ping command is used to try and reach a hostname that

4 ways to fix cd: no such file or directory

“cd: no such file or directory” is an error message that is displayed when the command line interpreter (CLI) is unable to find the directory

Bash Shell Script to Find IP address

A network interface is a point of interaction between a computer and a network. It can be a physical device, such as an Ethernet card

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, scanssh – fast ssh server and open proxy..., connect and disconnect wifi from commandline in linux, how to install and use putty on linux, how to find default gateway ip address in..., how to configure networking in vagrant, how to find available network interfaces on linux.

' 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

IMAGES

  1. Install Ubuntu Yaml 2022 2022

    how to set ip address linux

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

    how to set ip address linux

  3. How to Set a Static IP Address in Linux

    how to set ip address linux

  4. Set IP Address in Linux

    how to set ip address linux

  5. How to configure a fixed ip address using DHCP in Linux > BENISNOUS

    how to set ip address linux

  6. How To Find IP Address In Linux

    how to set ip address linux

VIDEO

  1. Fortuna Bio Terminal Network Setting

  2. Linux Tutorial: 53 Exploring ip address settings

  3. Assigning IP Address to a Computer

  4. How to Know IP address and Host Name in Linux

  5. How to Set A Static IP Address on Linux

  6. ASTER Workplaces IP Assignment

COMMENTS

  1. How To Change IP Address on Linux

    To change your IP address on Linux, use the “ifconfig” command followed by the name of your network interface and the new IP address to be

  2. How to Change IP Address in Linux

    Using the ip Command to Set an IP Address · Using Netplan for Network configuration (for Ubuntu) · Using Graphical Interface to Change the System

  3. How to Set a Static IP Address in Linux

    How to set your IP manually from the command line in Linux using both the old way (ifconfig) and the new way (ip/netplan).

  4. How to Assign an IP Address on a Linux Computer

    Change the item's IP address. Type in sudo ifconfig name ipaddress netmask 255.255.255.0 up —making sure to replace name with your item's name

  5. How to configure IP address in Linux

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

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

    This trick should work on all Debian-based Linux distros, including Ubuntu. To get started, type ifconfig at the terminal prompt

  7. 24 Useful "IP" Commands to Configure Network Interfaces

    To permanently configure a static IP address in Linux, you need to update or edit the network configuration file to assign a static IP

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

    Configure Static IP Address in RHEL/CentOS/Fedora: ... Where in the above "ifcfg-eth0" answers to your network interface eth0 . If your interface

  9. 3 Ways to change ip address in Linux

    To change IP address in Linux, we can use “ifconfig” command. Type ifconfig followed by the name of your network interface and the new IP

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

    1.1.1. Set Static IP Address By Editing Network Configuration File · BOOTPROTO="none"- This line shows that the network card's IP address should