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:

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.

David Cao

How to get AWS Instance ID

Understanding /etc/resolv.conf file in Linux

How to list repository in Linux

How to Find Your IP Address in Ubuntu Linux

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.

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

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

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

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

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 an ip address in linux

Written By Daniel Miessler

Recommended.

how to set an ip address in linux

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 Set a Static IP Address in Ubuntu

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

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

Linux laptop showing a bash prompt

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

Dynamic and Static IP Addresses Setting a Static IP Address in Ubuntu Using the GNOME Desktop and Applications Connection Convenience

Dynamic and Static IP Addresses

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

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

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

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

Setting a Static IP Address in Ubuntu

We’re demonstrating this technique on Ubuntu, but it ought to work on any Linux distribution. The nmcli network manager tool was released in 2004, so it should be present on just about any standard distribution.

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

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

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

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

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

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

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

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

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

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

The first command is a long one.

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

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

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

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

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

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

Here’s the output:

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

Using the GNOME Desktop and Applications

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

The available connections are displayed. A dot indicates which is in use. Our new connection is the active connection. Click the “Wired Settings” or “Wi-Fi Settings” menu option.

The details of the active connection are displayed. We can see our new “static-ip” connection has the IP address, default gateway, and DNS servers that we set for it. You can swap between the available connections by clicking directly on their names.

Click the cog icon to enter the settings for the “static-ip” connection.

A dialog box opens. Click on the “IPv4” tab.

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

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

A dialog appears. We need to provide a name for this connection.

We’re calling our new connection “static-2.” Click the “IPv4” tab.

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

Our new connection is listed in the “Wired” connections pane.

RELATED: How to Assign a Static IP Address in Windows 10 or 11

Connection Convenience

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

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

RELATED: How to Use bmon to Monitor Network Bandwidth on Linux

how to set an ip address in 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

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.

EDUCBA

Set IP Address in Linux

Balaji S

Introduction to Set IP Address in Linux

The Linux is a code that transmits the system commands., Compilers, Editors, linkers, and command-line interpreters are important and useful but they are not part of the operating system. An IP address is a path or identification for the user and the service provider. When using the internet, the website we want to load looks for our IP our Internet provider’s IP which is called a private IP address, and the information available from a website is called a private IP address.

A public IP address is a Wi-Fi system that provides internet and the mobile devices that connects to the same public IP will have their own private IP address. We can look briefly into the commands and techniques that are used to identify and set an IP address into a Linux system.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Course Curriculum

How to Set IP Address in Linux with Syntax?

Ip address is a unique digit or computer-based address that would identify a specific system in order to establish a connection.

IP command can perform multiple tasks such as network address assignment and parameters of network interface configuration.

The ip commands accommodate various facilities such as IP tunnel setup, modifying and configuring the routing of static and default ip, it can be used to list up IP property information and addresses, it can be used to configure or alter the interface status, it can delete, assign and it can set up routes and addresses.

Setting an IP address in Linux is very easy and we’ll look at certain commands to perform the action of setting an IP.

1. The If Configuration is used to manually set out the IP address

ifconfig etho 192.168.1.3 netmask 255.255.255.0 up

2. Setting our Gateway as default

route add default gw 192.168.1.1

3. We can set our DNS server by the following command

echo "nameserver 1.2.2.1" >/resolv.conf

If we are using a prior version Linux we can use our device to connect to the Internet and we have all our gateway and address fixed and we got out manually set IP address.

The public IP address of the server can be determined by sending a request to the HTTP servers on the Internet. By default, when a Linux system has interacted through the internet directly both the private and public IP addresses would remain the same. The ip commands have an advantage over the ipconfig commands since it ip command is powerful since it has backed up many more facilities and functionalities. The ip commands accommodate various facilities such as IP tunnel setup, modifying and configuring the routing of static and default ip, it can be used to list up IP property information and addresses, it can be used to configure or alter the interface status, it can delete, assign and it can set up routes and addresses.

Linux is an effectively operating system that has many advantages. It provides an interface to various tasks it is an open and free source without any cost and its comparatively secured over other operating systems. Linux can handle large volumes of data and it is used to deploy applications in the cloud environment.

We saw how to set our IP manually for both old versions using IF configuration and also in the new system using if and net plan configuration. Configuring IP address is an important skill for any network administrator. Once the IP address is set and we identify the IP address we can connect to any number of systems that have been connected through a common or one single network.

Recommended Articles

This is a guide to Set IP Address in Linux. Here we discuss how to set Set IP Address in Linux with appropriate syntax in detail. You can also go through our other related articles to learn more –

Sale

Related Courses

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy .

Forgot Password?

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Quiz

Explore 1000+ varieties of Mock tests View more

Submit Next Question

quiz

how to set an ip address in linux

How to Use IP Command in Linux with Examples

Home » SysAdmin » How to Use IP Command in Linux with Examples

Introduction

The ip command is a Linux net-tool for system and network administrators. IP stands for Internet Protocol and as the name suggests, the tool is used for configuring network interfaces.

Older Linux distributions used the ifconfig command , which operates similarly. However, ifconfig has a limited range of capabilities compared to the ip command.

In this tutorial, we go through all of the important operations the ip command can perform in Linux.

cheat sheet for ip commands for linux with examples

How to Use the ip Command

OBJECTS (or subcommands) that you will use most often include: 1. link ( l ) – used to display and modify network interfaces. 2. address ( addr/a ) – used to display and modify protocol addresses (IP, IPv6). 3. route ( r ) – used to display and alter the routing table. 4. neigh ( n ) – used to display and manipulate neighbor objects (ARP table).

There are many other objects and commands available. To see a full list type in the following command:

ip command options

To execute commands, you can use either full or abbreviated forms. For example, ip link and ip l will give the same results.

When configuring network interfaces, you must run the commands as root or a user with sudo privileges .

Warning: By default, the system does not retain the changes permanently. Once you restart a Linux Server , the newly modified state will be lost.

There are two ways to make your adjustments permanent: 1. add the commands to a startup script or 2. edit the distro-specific configuration files.

Manage and Display Network Interfaces

You can get a list of all below-mentioned link command options and more by typing:

list ip link commands

Get Network Interface Information

To see link-layer information of all available devices (which have a driver loaded) use the command:

If you want it to display the information for one specific device , type in the following:

To see statistics for all network interfaces (details such as transferred or dropped packets, or even errors) use:

You can also see similar information for an individual network interface with:

In case you need even more details , add another -s to the syntax:

To see a list of only the running interfaces use:

Modify Network Interface Status

If you want to bring a network interface up (online) , use the command:

Disable an interface (offline) by entering:

The ip link command allows you to modify the transmit queue , speeding up or slowing down interfaces to reflect your needs and hardware possibilities.

You can set the MTU (Maximum Transmission Unit) to improve network performance:

Find all the link command options by typing:

Monitor and Manage IP Addresses

Check out all below-mentioned address commands  and more by typing the following:

list of ip address commands

Monitor IP Addresses 

Display all devices by using the following command:

To list all network interfaces and the associated IP address , use the command:

You can also see information about an individual network :

To list the IPv4 addresses , use:

To list IPv6 addresses type:

How to Add IP Address in Linux

Add an IP address to an interface  using the command:

Note: If the interface specified does not exist, the output will display the Cannot find device [interface] message.

If you need to add a broadcast address to an interface use the command:

To remove an IP address from an interface type:

Manage and Display IP Routing Table

See a full list of ip route commands with the following command:

list route commands

Display IP Routing Table

List all the route entries use either of the following commands:

With the commands above, the output displays all of the route entries in the kernel. If you need to narrow down the search, add the SELECTOR object:

Note: SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ] [ table TABLE_ID ] [ proto RTPROTO ] [ type TYPE ] [ scope SCOPE ]

To view  routing for a distinct network , use the following syntax:

Modify IP Routing Table

To add a new entry in the routing table that can be reached on a specific device, type in the command:

Or you can add a new route via gateway by typing:

Also, the command allows you to add a route for all addresses via the local gateway by adding the default option:

To delete an existing entry in the routing table, use the commands:

Display and Modify IP Neighbor Entries

Neighbor entries tie the protocol address and the link-layer addresses under the same link. Organized into IPv4 tables, they are also called ARP (Address Resolution Protocol) tables.

For a full list of all neigh command options use:

list neigh commands

Display IP Neighbor Entries

To display neighbor tables , use the following command:

The output shows the MAC addresses of devices which are part of the system and their state. The state of a device can be:

Modify IP Neighbor Entries

Add a new table entry with the command:

Or, remove an existing ARP entry :

You now know what the IP command in Linux is and how to use the command to assist in network/system administration.

Next, discover more Linux Commands in our Cheat Sheet and Tutorial With Examples .

how to set an ip address in linux

Linux Shell Tips – The Best Linux Command Line Web Portal

How to Set a Static IP Address in CentOS Linux

' src=

An IP ( Internet Protocol ) Address is a unique numerical representation of a computer on a network. Every computer connected to the Internet is identified by an IP Address.

Usually, IP addresses are dynamically assigned to a computer by a dedicated server called DHCP Server ( Dynamic Host Control Protocol ), and hence change from time to time as and when the connection is lost and reestablished.

However, there are scenarios where a static IP address is more preferable; Eg. In large corporations, where it removes the load of using DHCP for each computer in the organization.

Today, we will learn how to set a static IP address on a local network in CentOS .

List Network Interface Name

A computer can be connected to one or more network interfaces, for example to a WiFi device and a LAN device, which has different IP addresses for each interface.

Run the following command to show the interface names.

List Network Interface Names

The interface ‘ enp0s3 ‘ is the LAN device connected to my computer and the IP Address is ‘ 10.0.2.15 ‘. The other interface ‘ lo ‘ ( Loopback ) which is nothing but the local network of the computer within itself. Thus my computer is only connected to one interface, ‘ enp0s3 ‘.

Configuring Static IP Address in CentOS

Go to directory ‘ /etc/sysconfig/network-scripts ‘ and list the files; you should see a file corresponding to your network interface.

List Network Interface Files

Open the file ‘ifcfg-enp0s3’ using ‘ Vim ‘ or any editor of your choice.

Set the following values for the variables. Change the values according to the IP address and subnet that you need to set.

Set IP Address in CentOS

Save and exit the file. Restart the networking service with the following commands:

Finally, run ‘ ifconfig ‘ again to verify if static IP has been set.

Verify IP Address in CentOS

In this article, we saw an easy way to set an IP address in CentOS. The example, in this case, is a static IP on the local network, i.e., it is not a static public IP over the Internet.

To set a static public IP address over the Internet, you need to purchase the IP Address and configure it in the file as shown above, along with other details like DNS server, network prefix, which will be provided by your Internet Service Provider.

Thanks a lot for reading and let us know your thoughts in the comments below!

Tutorial Feedback...

Recommended articles.

What are CentOS and CentOS Stream and History

How to Create Sudo User in RHEL, CentOS, Rocky & AlmaLinux

How to Install Remi Repo in RHEL, CentOS, Rocky, & AlmaLinux

How to Install Suricata on RHEL, Rocky & AlmaLinux

How to Install FTP with SSL in Rocky Linux and AlmaLinux

Learn Different Networking Options in VirtualBox

How to Install Guest Additions in Virtualbox VM

How to Install CentOS 7 Minimal in Virtualbox

How to Host a Website on NGINX Web Server

How to Host a Website on an Apache Web Server

Got Something to Say? Join the Discussion... Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

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.

Stack Exchange Network

Stack Exchange network consists of 181 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

How can I change the IP and gateway addresses permanently?

I recently installed Linux Ubuntu 14.04 to my computer. To enable internet connection I needed to change my IP and Gateway address. I did the following as a root user

It works fine for a couple of minutes but then goes back to the previous settings every time. So, How can I change the IP and the gw addresses permanently?

Anthon's user avatar

2 Answers 2

As stated by jpkotta, network-manager is likely the culprit.

You can see its status by running ps -aux | grep network-manager | grep <username> . If you get a result, it is running, otherwise it isn't.

It will keep overwriting any changes you make with ifconfig as long as it is running.

Kill network-manager by running sudo service network-manager stop . You can bring it back up any time with sudo service network-manager start .

Once it is disabled, use ifconfig to set your static, OR edit your /etc/network/interfaces file to include something like:

Finally, run ifup -a to bring up the interfaces you have in your /etc/network/interfaces file.

All of this can be avoided though, if you'd rather not mess around with killing network manager. Just click on its icon in the taskbar and click 'edit connections'.

cremefraiche's user avatar

Commands which you have to fire are:

Check your NIC ifconfig

Choose one and set it with ip which you want to give: ifconfig enp0s8 192.168.1.34

go to cd /etc/sysconfig/network-scripts/

edit NIC file:

vim ifcfg-enp0s8

'IPADDR' = 192.168.1.34 'NETMASK'= 255.255.255.0 'ONBOOT' = yes 'BOOTPROTO'= 'static'

Community'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 command-line ip or ask your own question .

Hot Network Questions

how to set an ip address 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 .

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Azure Linux vm ifconfig shows a different IPv6 address than the one I set in the console

I set private ipv6 IP is began with ace:ceb but i type ifconfig in vm it shows that vm's ipv6 address is began with fe80:: but ipv4 address is normal I set v4 address is 10.1.1.5 and ifconfig show the same addr

Azure Virtual Machines An Azure service that is used to provision Windows and Linux virtual machines. 4,772 questions Sign in to follow

Azure Virtual Network An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters. 1,238 questions Sign in to follow

The IPv6 address that begins with "fe80::" is a link-local address, which is used for communication within the local network segment.

Please verify that you have an IPv6 private address associated with the Network Interface. You should see this when viewing the IP configurations of the NIC. If not, you can add the IPv6 here.

User's image

If you have IPv6 private address associated with the NIC and are still not seeing it on the VM you will need to update the OS configuration. This page walks you through enabling DHCPv6 for your VM.

Hope this helps! Let me know if you still have questions or issues.

Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

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.

Systran Box

 How To Get IP Address Of Linux Machine Using Java

How To Get IP Address Of Linux Machine Using Java

If you’re a Java developer working in a Linux environment, you may be wondering how to get the IP address of your computer. Acquiring an IP address is an important task, especially if you’re running a web application or a network-based application on a machine that’s connected to the internet. Fortunately, getting the IP address of your Linux machine is relatively easy with the help of the Java language and its associated APIs. This tutorial will explain how to get the IP address of your Linux machine using Java.

I previously used the InetAddress class, which is a bad solution for cross-platform applications. When this code is typed, it generates a list of all network interface addresses. You should not return the first non-loopback interface, which may have been created by some software, such as Parallels. Java supports the use of InetAddress.

How To Get Ip Address Through Java?

How To Get Ip Address Through Java?

It is necessary to get the Ip Address and Inet Address of the current Server that is currently running the Java app. GetHostName() will return the current Server Hostname . In this Java programming tutorial, we will look at the Java.net package to learn some networking fundamentals.

Java Get Local Ip Address Linux

Java Get Local Ip Address Linux

Java provides several methods to retrieve a device’s local IP address in Linux. The InetAddress class, which is part of the java.net package, has a getLocalHost() method which will return a InetAddress object containing the local host’s address. Another option is to use the NetworkInterface class , which is also part of the java.net package, to get a list of all the network interfaces on the system, and then use one of the getInetAddresses() methods to get the address. Finally, the Socket class also contains a getLocalAddress() method which can be used to retrieve the local IP address of the device.

An Internet connection can be distinguished by two methods: its network name, or LAN, WAN, or other name. In Java, it is simple to write a program that finds the IP address of a local host. In this article, we will learn how to find an IP address of any Java machine. The InetAddress class encapsulates both the IP address and the hostname information. If you’re using a different computer name than the default localhost name, you can get that name by calling getHostName() method. As a result, java.net may be thrown. If the name localhost is not specified in the /etc/host file, an UnknownHostException occurs. If you are a Java developer looking for the local IP address of your Linux system, you are in luck.

Find Your Local Ip Address On Linux With Java

You can determine your local IP address with a few simple commands. The getLocalHost() method is a Java API that can be used to determine whether the private IP addresses used in LANs or any other local network are present. Linux users can view their IP address with the help of the hostname, ifconfig, or ip commands. In this example, use the command -I to enter the server name. This address is returned to you as 192.168.122.237. Using this information, you can quickly and easily determine the IP address of your Linux system. InetAddress can be used in Java.

How To Get Server Ip Address In Java

How To Get Server Ip Address In Java

To get the Server IP address in Java, you will need to use the InetAddress class. First, create an InetAddress object using the static method getLocalHost(). Then, you can use the getHostAddress() method of the InetAddress object to obtain the IP address of the server. Finally, you can print the IP address using the toString() method. This should provide you with an easy and straightforward way to get the Server IP address in Java.

How To Get Ip Address From String In Java

How To Get Ip Address From String In Java

In Java, you can use the InetAddress class to get the IP address from a string. First, create a new InetAddress object and pass the string representation of the URL or hostname as an argument. Then, use the getHostAddress() method to retrieve the IP address from the InetAddress object. The returned IP address will be a String. To ensure that the IP address is valid, use the InetAddress.isReachable() method to check if the IP address is reachable.

Uncovering Ip Addresses In Java

It is most commonly used to find private IP addresses within a LAN or other local network using the InetAddress.getLocalHost() method. A connection can be created between two devices on the same network by using this method. An online utility called http://bot.whatismyipaddress.com can be used to extract a public IP address. Using the getByName() method, a valid public IP address can also be obtained from a specific host. As a result, this method can be used to obtain the IP address of a host from a Java URL. The two methods we have chosen are both simple and provide a cost-effective way to obtain the IP address of a website or host. IP addresses are Internet Protocol addresses , which are dots that represent the number range of Internet Protocol addresses.

Java Get All Ip Addresses

Java Get All Ip Addresses

Java can be used to retrieve all IP addresses associated with a particular device. This is useful for a variety of purposes, such as gathering all IP addresses associated with a server or network or checking which IP addresses are assigned to particular devices. Java’s InetAddress class, along with several related classes, make it easy to retrieve a list of all IP addresses associated with a device. It can also be used to determine if a particular IP address is reachable or not. With this information, you can quickly identify or troubleshoot any IP address-related issues.

The Domain Name System (DNS) is a TCP/ IP protocol that governs how messages are processed. DNS enables users to connect to all websites by retaining their domain names’ corresponding hosts. To gain access to the DNS server, you must have an e-mail client or web browser installed on your computer. The InetAddress method connects to a local DNS server to retrieve or send information to the system. If an InetAddress.getHostName() method cannot be used to locate the host, an UnknownHostException is generated. This results in some issues, such as a missing host. When the first attempt fails, the data is still being transmitted from the remote DNS server, which causes this error. The most straightforward way to find your public IP address in Java is to open a web page.

Discovering Your Public Ip Address In Java

You can locate the IP address by using http://bot.whatismyipaddress.com. Following that, you can use Windows, macOS, or Linux to find all active IP addresses on your network. Please enter ipconfig or ifconfig into your terminal to accomplish this. The subnet mask, the default gateway, and the IPv4 address of your computer are all listed under this section. Finally, use the command arp -a to determine which other IP addresses are on your network. After following these steps, you should be able to find your public IP address in Java. It is possible to query the network interface rather than the machine.

Java Get Public Ip Address

Java Get Public Ip Address

Java is a powerful programming language that allows developers to access public IP addresses. With Java’s networking capabilities, developers can access a public IP address, and use it for various purposes. For example, a developer may need to access a public IP address to create a web server, or create a client-server application. Java also provides various methods to get public IP addresses, such as using the InetAddress class, or using the System class. With Java’s powerful capabilities, developers can access public IP addresses with ease.

Your NAT box, which is linked to your computer’s internal IP address mapping , does not communicate with its kernel. Simply use existing services to do the same; a website can be written and run with code that returns the IP of the request; and request.getRemoteAddr() can be used to return the request’s IP. External ip can be used to deploy a JAVA-based webapp that will fetch the client’s (One who makes the request via a browser) requests. It is necessary to use a remote addr to read the external IP address. An external command can be used instead of an internal command, which is obviously an inconvenient solution. A device’s or client’s IP address is an important piece of information for web applications to use.

Getting Public Ip Addresses With Java

To accomplish this, Java can use a simple URL request, which is http://bot.whatismyipaddress.com. This website displays the device’s public IP address. To obtain the IP address of a client, use the HttpServletRequest.getRemoteAddr() method in Java. The IP address of a client accessing the web application is returned by this method. Java can easily retrieve the public IP address of the client as well as the client’s IP address from this method. You can begin using your phone for a variety of tasks such as powering a LAMP server and creating a portable network by using a fully functional Linux program.

How To Get Client Ip Address In Java Spring Boot

Getting the client IP address in Java Spring Boot is relatively straightforward. First, you need to get the HttpServletRequest object from the controller method argument. From the HttpServletRequest object, you can use the getRemoteAddr() method to get the client IP address. It is important to note that this method will only work if the request has been routed through an HTTP proxy or load balancer, otherwise the IP address may not be accurate. To ensure accuracy, it is recommended to use the getHeader(“X-Forwarded-For”) method which will provide a list of IP addresses that the request has been routed through. Using the list of IP addresses, you can determine the client IP address by taking the first address in the list.

Travis is a programmer who writes about programming and delivers related news to readers. He is knowledgeable and experienced, and he enjoys sharing his knowledge with others.

How to Check the IP Address in Linux

Last Updated: March 13, 2020 Tested

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 24,098,881 times. Learn more...

This wikiHow teaches you how to view your computer's private and public IP addresses on a Linux computer.

Finding Your Public IP Address

Image titled Understandmethod

Finding Your Private IP Address

Image titled Understand5

Image titled Check the IP Address in Linux Step 7

Community Q&A

Pingu

how to set an ip address in linux

You Might Also Like

Assign an IP Address on a Linux Computer

About This Article

Jack Lloyd

To check your public IP address in Linux, start by clicking the Terminal app icon or simultaneously pressing “Control,” “Alt,’ and “T” to bring up the Terminal window. Once the Terminal window is open, enter the public IP command "curl ifconfig.me" to retrieve your address from a website. Press “Enter” to run the command, and wait for your public IP address to appear. Alternatively, to find your private IP address, bring up the terminal window and enter the Show IP command "ifconfig." Press Enter to run your command and display the IP address information of any network items, including your computer. In order to find your computer’s heading, look under the “wlo1” heading and review the private IP address. To learn how to use the “hostname” command to bring up your computer’s IP address, keep reading! Did this summary help you? Yes No

Reader Success Stories

Roland Weber

Roland Weber

Sep 6, 2016

Is this article up to date?

Roland Weber

Abdullah Bashnain

Jun 12, 2017

Anonymous

Dec 17, 2017

Aug 18, 2017

Jan 4, 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

Get updates via: rss | twitter | email

Set IP address Linux Using ip command

Written by Guillermo Garron Date: 2012-04-25 11:28:00 00:00

How to add or set the IP address in Linux using the ip command?

You better start getting used to use the ip command as some Linux distributions have started deprecating the ifconfig command.

So, if you want to set the IP in your Linux box, run:

The first line, sets the IP, be sure to replace "10.1.1.2/16" with the IP and mask bits, you need to use.

The second line, brings the link up.

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.

IMAGES

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

    how to set an ip address in linux

  2. Set IP Address in Linux

    how to set an ip address in linux

  3. How to Set a Static IP Address in Linux

    how to set an ip address in linux

  4. How To Find IP Address In Linux

    how to set an ip address in linux

  5. Set IP Address in Linux

    how to set an ip address in linux

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

    how to set an ip address in linux

VIDEO

  1. Fortuna Bio Terminal Network Setting

  2. Command to show IP of Linux Server ?

  3. Assigning IP Address to a Computer

  4. How to Set A Static IP Address on Linux

  5. ASTER Workplaces IP Assignment

  6. Konfigurasi IP Address

COMMENTS

  1. How to Change IP Address in Linux

    The ip command is available on most Linux distributions. For setting an IP address, use it like this: ip addr add [ip_address] dev [interface] For example, add an IP address to the eth1 interface as: sudo ip addr add 192.168.56.21/24 dev eth1 You now have two IP addresses: one from the old configuration and one from the new command:

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

    Depending on your Linux version, you may have several ways of opening Terminal: 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.

  3. 3 Ways to change ip address in Linux

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

  4. How to Set a Static IP Address in Linux

    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… ip a (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 ip -4 a

  5. How to Use the ip Command on Linux

    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:

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

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

    Open that file and set: NETWORKING=yes HOSTNAME=node01.tecmint.com GATEWAY=192.168..1 NETWORKING_IPV6=no IPV6INIT=no Next open: # vi /etc/sysconfig/network-scripts/ifcfg-eth0 Note: Make sure to open the file corresponding to your network interface. You can find your network interface name with ifconfig -a command.

  8. How To Change IP Address on Linux

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

  9. How to Set IP Address in Linux with Syntax?

    Setting an IP address in Linux is very easy and we'll look at certain commands to perform the action of setting an IP. 1. The If Configuration is used to manually set out the IP address ifconfig etho 192.168.1.3 netmask 255.255.255. up 2. Setting our Gateway as default route add default gw 192.168.1.1 3.

  10. Linux ifconfig Command

    Use the following syntax to assign the IP address and netmask: ifconfig [interface-name] [ip-address] netmask [subnet-mask] For example, to assign the IP address 192.168..101 and netmask 255.255.. to the interface eth0, you would run: ifconfig eth0 192.168..101 netmask 255.255..

  11. Setting up static IP address for Linux: Easier than you think

    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.

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

    auto eth1 enables automatic configuration for this interface during boot. iface eth1 inet static sets eth1 as an IPv4 interface with a static address. address, netmask, and gateway assign the respective addresses and network. dns-nameservers, while not strictly necessary, sets the DNS servers to use.

  13. Linux IP Command Ultimate Tutorial with 31 Examples

    How to Use the ip Command. 1. link ( l) - used to display and modify network interfaces. 2. address ( addr/a) - used to display and modify protocol addresses (IP, IPv6). 3. route ( r) - used to display and alter the routing table. 4. neigh ( n) - used to display and manipulate neighbor objects (ARP table).

  14. Linux ip Command Examples

    You can set loopback address to the loopback device lo as follows: ip addr add 127.0.0.1/8 dev lo brd + scope host. Remove / Delete the IP address from the interface. The syntax is as follows to remove an IPv4/IPv6 address: ip a del {ipv6_addr_OR_ipv4_addr} dev {interface} To delete 192.168.1.200/24 from eth0, enter: ip a del 192.168.1.200/24 ...

  15. How to Set a Static IP Address in CentOS Linux

    Run the following command to show the interface names. # ifconfig OR # ip addr List Network Interface Names. The interface 'enp0s3' is the LAN device connected to my computer and the IP Address is '10.0.2.15'.The other interface 'lo' (Loopback) which is nothing but the local network of the computer within itself.Thus my computer is only connected to one interface, 'enp0s3'.

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

    Note down the Debian Linux interface name and type the following ip command to see the current IP address assinged to that network interface: ip -c addr show enp0s5 Finding NIC name and IP assigned by the DHCP server on Debian Linux

  17. linux

    All of this can be avoided though, if you'd rather not mess around with killing network manager. Just click on its icon in the taskbar and click 'edit connections'. Choose one and set it with ip which you want to give: ifconfig enp0s8 192.168.1.34. There is already a more valid, complete, and well formatted answer.

  18. Azure Linux vm ifconfig shows a different IPv6 address than the one I

    I set private ipv6 IP is began with ace:ceb but i type ifconfig in vm it shows that vm's ipv6 address is began with fe80:: but ipv4 address is normal I set v4 address is 10.1.1.5 and ifconfig show the same addr

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

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

  20. How to Assign Static IP Address on Ubuntu Linux

    Method 2: Switch to static IP address in Ubuntu graphically. If you are on desktop, using the graphical method is easier and faster. Go to the settings and look for network settings. Click the gear symbol adjacent to your network connection. Next, you should go to the IPv4 tab.

  21. How To Get IP Address Of Linux Machine Using Java

    In Java, you can use the InetAddress class to get the IP address from a string. First, create a new InetAddress object and pass the string representation of the URL or hostname as an argument. Then, use the getHostAddress () method to retrieve the IP address from the InetAddress object. The returned IP address will be a String.

  22. How to Check the IP Address in Linux: 12 Steps (with Pictures)

    Click or double-click the Terminal app icon, or press Ctrl + Alt + T to bring up the Terminal window. 3. Enter the public IP command. Type curl ifconfig.me into the Terminal window. This command retrieves your public IP address from a website. [1] 4. Press ↵ Enter.

  23. Set IP address Linux Using ip command

    How to add or set the IP address in Linux using the ip command? You better start getting used to use the ip command as some Linux distributions have started deprecating the ifconfig command. So, if you want to set the IP in your Linux box, run: ip addr add 10.1.1.2/16 dev eth1 ip link set eth1 up

  24. Quick Answer: How To Assign Ip Address In Linux Command Line?

    How do I set a valid IP address? Solution 4 - Set your IP address manually. Press Windows Key + X and choose Network Connections. Right click your wireless network and choose Properties from the menu. Select Internet Protocol Version 4 (TCP/IPv4) and click the Properties button.

  25. Different methods to set Static IP Address

    Set Static IP in Rocky Linux [6 Different Methods] Written By - admin. Different methods to set Static IP Address - Rocky Linux 8. Method-1: Manually Edit Network Interface Config File. Method-2: Configure Static IP Address using ifconfig. Method-3: Configure Static IP using ip command. Method-4: Configure Static IP using ifcfg Utility.