Daniel Miessler

How to Set a Static IP Address in Linux
Created/Updated: February 2, 2022

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

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

- EXPLORE Coupons Tech Help Pro Random Article About Us Quizzes Contribute Train Your Brain Game Improve Your English Popular Categories Arts and Entertainment Artwork Books Movies Computers and Electronics Computers Phone Skills Technology Hacks Health Men's Health Mental Health Women's Health Relationships Dating Love Relationship Issues Hobbies and Crafts Crafts Drawing Games Education & Communication Communication Skills Personal Development Studying Personal Care and Style Fashion Hair Care Personal Hygiene Youth Personal Care School Stuff Dating All Categories Arts and Entertainment Finance and Business Home and Garden Relationship Quizzes Cars & Other Vehicles Food and Entertaining Personal Care and Style Sports and Fitness Computers and Electronics Health Pets and Animals Travel Education & Communication Hobbies and Crafts Philosophy and Religion Work World Family Life Holidays and Traditions Relationships Youth
- HELP US Support wikiHow Community Dashboard Write an Article Request a New Article More Ideas...
- EDIT Edit this Article
- PRO Courses New Guides Tech Help Pro New Expert Videos About wikiHow Pro Coupons Quizzes Upgrade Sign In
- Premium wikiHow Guides
- Browse Articles
- Quizzes New
- Train Your Brain New
- Improve Your English New
- Support wikiHow
- About wikiHow
- Easy Ways to Help
- Approve Questions
- Fix Spelling
- More Things to Try...
- H&M Coupons
- Hotwire Promo Codes
- StubHub Discount Codes
- Ashley Furniture Coupons
- Blue Nile Promo Codes
- NordVPN Coupons
- Samsung Promo Codes
- Chewy Promo Codes
- Ulta Coupons
- Vistaprint Promo Codes
- Shutterfly Promo Codes
- DoorDash Promo Codes
- Office Depot Coupons
- adidas Promo Codes
- Home Depot Coupons
- DSW Coupons
- Bed Bath and Beyond Coupons
- Lowe's Coupons
- Surfshark Coupons
- Nordstrom Coupons
- Walmart Promo Codes
- Dick's Sporting Goods Coupons
- Fanatics Coupons
- Edible Arrangements Coupons
- eBay Coupons
- Log in / Sign up
- Computers and Electronics
- Operating Systems
How to Assign an IP Address on a Linux Computer
Last Updated: July 28, 2022 Tested
Debian, Ubuntu, & Linux Mint
Red hat, centos, & fedora.
This article was co-authored by wikiHow staff writer, Jack Lloyd . Jack Lloyd is a Technology Writer and Editor for wikiHow. He has over two years of experience writing and editing technology-related articles. He is technology enthusiast and an English teacher. The wikiHow Tech Team also followed the article's instructions and verified that they work. This article has been viewed 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.

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

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

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

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

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

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

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

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

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

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

Expert Q&A
Video . by using this service, some information may be shared with youtube..
- Some very specific Linux distributions will require you to go through a different process to assign an IP address. To see your specific distribution's specifications, check online. ⧼thumbs_response⧽ Helpful 0 Not Helpful 0

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

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

- Send fan mail to authors
Reader Success Stories

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

Dmitry Ugay
Oct 10, 2017

Featured Articles

Trending Articles

Watch Articles

- Terms of Use
- Privacy Policy
- Do Not Sell or Share My Info
- Not Selling Info
wikiHow Tech Help Pro:
Level up your tech skills and stay ahead of the curve
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.

To learn more about the 'ip addr' command, you can check the following tutorial.
Linux ip address Command Usages and Examples
Setting a permanent IP address
There are four methods to configure a permanent IP address. These methods are: -
- Changing the configuration file
- Using the nmcli command
- Using the nmtui utility
- Using the nn-connection-editor tool
Let's discuss each method in detail.
Changing IP addresses in configuration files
Linux uses a configuration file for each interface to store its configuration. It stores all configuration files in /etc/sysconfig/network-scripts directory. For the naming convention of interface configuration files, it uses the 'ifcfg' prefix. After this prefix, it uses the name of the network card. For example, if the interface's name is ens160 , it will store its configuration in the ifcfg- ens160 file.

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.

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.

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.

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.

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

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

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

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

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

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

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

Select the Quit option and press the Enter key.

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.

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

Now use the following steps to add/update/edit IP configuration on the selected interface.
- Switch to the IPv4 Settings.
- Select the Manual option from the Method drop-down menu.
- Click the Add button and configure IP addresses in respective fields.
- Click the Save button.
- Click the Close button on the main screen.

Restart the interface and verify the new IP configuration.

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]
- Buying Guides
Complete Guides by How-To Geek
Our latest product roundups, reader favorites, more from how-to geek, latest geek news, latest reviews, across lifesavvy media.
Join 425,000 subscribers and get a daily digest of news, geek trivia, and our feature articles.
By submitting your email, you agree to the Terms of Use and Privacy Policy .
How to 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...

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 Delete Your Google Chrome Incognito Browsing History
- › Microsoft Edge 111 Arrives With Bing AI and Edge Copilot
- › Amazon’s Satellite Internet Won’t Need a Giant Antenna
- › How to Print Text Messages From Android
- › Google-Owned Waze Will Help You Find EV Chargers
- › How to Remove Bing Chat “Discover” Button in Microsoft Edge


How to Set Static IP Address and Configure Network in Linux
If you are a Linux system administrator, time will come when you will need to configure networking on your system. Unlike desktop machines where you can use dynamic IP addresses, on a server infrastructure, you will need to setup a static IP address (at least in most cases).
Read Also: How to Set or Change System Hostname in Linux </p
This article is meant to show you how to configure static IP address on most frequently used Linux distributions.
For the purpose of this tutorial, we will use the following Internet Protocol version 4 (IPv4) details:
Configure Static IP Address in RHEL/CentOS/Fedora:
To configure static IP address in RHEL / CentOS / Fedora , you will need to edit:
Where in the above "ifcfg-eth0" answers to your network interface eth0 . If your interface is named “ eth1" then the file that you will need to edit is "ifcfg-eth1" .
Let’s start with the first file:
Open that file and set:
Note : Make sure to open the file corresponding to your network interface. You can find your network interface name with ifconfig -a command .
In that file make the following changes:
You will only need to edit the settings for:
- DNS1 and DNS2
Other settings should have already been predefined.
Next edit resolve.conf file by opening it with a text editor such as nano or vi :
Once you have made your changes restart the networking with:
Set Static IP Address in Debian / Ubuntu
To setup static IP address in Debian / Ubuntu , open the following file:
You may see a line looking like this:
Change it so it looks like this:
Save the file and then edit /etc/resolv.conf like this:
Restart the networking on your system with:
Your static IP address has been configured.
Conclusion:
You now know how to configure a static IP address on a Linux distro. If you have any questions or comments, please do not hesitate to submit them in the comment section below.
Tutorial Feedback...
If you appreciate what we do here on tecmint, you should consider:.
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.
Related Posts

How to Create a Systemd Service in Linux

How to Create Device Files in Linux Using mknod Command

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

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

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

How to Run Commands from Standard Input Using Tee and Xargs in Linux
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.
- Last updated: February 27, 2023
- Cloud , 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!
- ifconfig eth0 192.168.0.100 netmask 255.255.255.0
- ip addr add 192.168.0.100/24 dev eth0
- change ip address in file /etc/sysconfig/network-scripts/ifcfg-eth0 and restart network systemctl restart network
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:
- Open the terminal application.
- List the current IP addresses for all network interfaces with command ifconfig -a
- Take the network interface down with command: ifconfig <interface> down
- Change the IP address with command ifconfig <interface> <ip address> <netmask>
- Press Enter to run the command.
- Verify that the new IP address is correct with command ifconfig -a
- Take the interface up with command ifconfig <interface> up
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.
- Open up your VPN application.
- Select which server you want to connect to. If you’re just looking for privacy, choose one in your home country. If you want to access content from another country, pick one in your desired location.
- Press the connect button — it should be easy to find.
- Wait a few seconds for the VPN to connect. You’ll now be using a new IP address.
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
- Open Source
- Free Ebooks And Videos
How To Configure Static IP Address In Linux And Unix
3 different ways to set static ip address in linux and freebsd.
Setting IP address after a fresh Linux installation is one of the mandatory skill that every Linux and Unix administrator should learn. We can easily assign IP address in Linux that has GUI mode. However, configuring IP networking from command line mode is entirely different! This step by step tutorial describes how to configure static IP address in Linux and Unix operating systems from command line mode.
The steps provided below are tested on AlmaLinux 8, CentOS 8 server editions, Ubuntu 22.04, 18.04, and 16.04 server and desktop editions and FreeBSD 13, FreeBSD 12 server editions. However, it should work on most RPM-based and DEB-based Linux systems and BSD flavors.
1. Configure Static IP Address In Linux
Setting up IP address in RPM-based and DEB-based systems is little bit different. First, we will see how to configure IP address on RPM-based systems.
1.1. Assign Static IP address In Fedora, RHEL, CentOS, AlmaLinux, Rocky Linux
Assigning IP address in Fedora and RHEL-based systems can be done with different ways. We can set IP address,
- by manually editing the network configuration file,
- using Nmcli command line tool,
- and using Nmtui text-based user interface tool.
1.1.1. Set Static IP Address By Editing Network Configuration File
In Fedora, RHEL and its clones like CentOS, AlmaLinux and Rocky Linux, the network interface card (shortly NIC ) configuration are stored under /etc/sysconfig/network-scripts/ directory.
Note: Here, I run all commands as root user. If you logged-in as normal user, just prepend each command with ' sudo ' .
First, let us find the name of the network card.
To do so, run:
Sample output:
Or, use this command to display detailed output:
Usually, the wired network card name will start with letter "e" , and wireless card name will start letter with "w" .
As you see in the above output, my wired network card name is enp0s3 . It might be different in your distribution, but it usually start with letter "e".
Let us now configure a static IP address to this NIC.
Open the network card config file in any editor:
Here, I use vi editor to edit the network config file. You can use any text/graphical editor of your choice, for example nano or gedit .
Set bootproto (boot protocol) to none and set the IP address, subnet mask, gateway, and DNS server as shown below.

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

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

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

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

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

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

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

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

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

Senthilkumar Palani (aka SK) is the Founder and Editor in chief of OSTechNix. He is a Linux/Unix enthusiast and FOSS supporter. He lives in Tamilnadu, India.
How To Perform Arithmetic Operations In Bash
How to change user password in linux, you may also like, 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.

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

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

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

What ip adress re we supposed to enter in when configuring the static ip ?
Any IP address of your choice.
Leave a Comment Cancel Reply
Save my name, email, and website in this browser for the next time I comment.
This site uses Akismet to reduce spam. Learn how your comment data is processed .
This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More

IMAGES
VIDEO
COMMENTS
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
Using the ip Command to Set an IP Address · Using Netplan for Network configuration (for Ubuntu) · Using Graphical Interface to Change the System
How to set your IP manually from the command line in Linux using both the old way (ifconfig) and the new way (ip/netplan).
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
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
This trick should work on all Debian-based Linux distros, including Ubuntu. To get started, type ifconfig at the terminal prompt
To permanently configure a static IP address in Linux, you need to update or edit the network configuration file to assign a static IP
Configure Static IP Address in RHEL/CentOS/Fedora: ... Where in the above "ifcfg-eth0" answers to your network interface eth0 . If your interface
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
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