• EXPLORE Coupons Tech Help Pro Random Article About Us Quizzes Request a New Article Community Dashboard This Or That Game 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
  • EDIT Edit this Article
  • PRO Courses Guides New Tech Help Pro Expert Videos About wikiHow Pro Upgrade Sign In
  • Browse Articles
  • Learn Something New
  • This Or That Game New
  • Train Your Brain
  • Explore More
  • Support wikiHow
  • About wikiHow
  • 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 709,718 times. Learn more...

This wikiHow teaches you how to assign a new IP address to your computer when using Linux. Doing so can prevent connection issues for the item in question.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  • 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

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

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

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

Expert Q&A

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

  • 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. Thanks Helpful 0 Not Helpful 0

how to assign ip address to eth0 in linux

  • Don't forget to switch back to the regular (non-root) user account when you're done. Thanks Helpful 1 Not Helpful 1

You Might Also Like

Set up a Network in Ubuntu

  • ↑ https://danielmiessler.com/study/set_ip/
  • ↑ https://www.youtube.com/watch?v=oQd5eG9BZXE&t=

About This Article

Jack Lloyd

  • Send fan mail to authors

Reader Success Stories

Buddy HaDagi

Buddy HaDagi

Jan 27, 2017

Is this article up to date?

Buddy HaDagi

Dmitry Ugay

Oct 10, 2017

Am I a Narcissist or an Empath Quiz

Featured Articles

Prepare for Chemotherapy

Trending Articles

How to Delete the Cache in YouTube: Desktop & Mobile App

Watch Articles

Make Crispy Cookies

  • Terms of Use
  • Privacy Policy
  • Do Not Sell or Share My Info
  • Not Selling Info

Keep up with the latest tech with wikiHow's free Tech Help Newsletter

Stack Exchange Network

Stack Exchange network consists of 183 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.

use dhcp on eth0 using command line

I am trying to set the eth0 interface to use dhcp to get an ipv4 address, using the command line. I can manually change the ip address using

Is there a similar command to use to set eth0 to get an address using dhcp? I tried typing:

however the ip address doesn't change when I type this. The /etc/network/interfaces file was set to

which I then changed to:

however this doesn't change the eth0 ip address even if the system is rebooted.

thrig's user avatar

2 Answers 2

If your dhcp is properly configured to give you an IP address, the command:

should work. The option -v enable verbose log messages, it can be useful.

If your eth0 is already up, before asking for a new IP address, try to deconfigure eth0 .

To configure the network interfaces based on interface definitions in the file /etc/network/interfaces you can use ifup and ifdown commands.

andreatsh's user avatar

First you need to run the following command:

Then change the ip adress:

Change xx.xx.xx.xx with the needed ip_adress

GAD3R's user avatar

You must log in to answer this question.

  • Featured on Meta
  • Our Design Vision for Stack Overflow and the Stack Exchange network

Hot Network Questions

  • Making caramel sauce with yogurt instead of milk
  • Pass result of find command as another command's multiple options
  • Are all homotopy equivalences realized by fibrations over [0,1]?
  • Was the recent ruling against Jordan Peterson an infringement of his free speech?
  • Wrongly got exit stamp from Schengen zone
  • "has had a newborn baby"?
  • Is this duplo train track under too much tension?
  • expl3: vlists, galleys, boxes and coffins: what they are and how they interact
  • How can I pass a statistics exam that overly relies on memorizing formulas?
  • How can I use Windows .bat files to create folder above current folder?
  • Why can't I get self drilling anchors into the wall
  • Why do people do a postdoc, rather than getting another PhD?
  • Changing mono font with PDFLaTeX
  • Why does Canada's superficial loss rule also include a clause for "30 days before the sale"?
  • How can I add a circle along the planes?
  • Is this possible to boot an OS from some kind of a file?
  • Geometry nodes, how to flat mesh islands on z axis
  • Male and female seahorses: which is which
  • Correct way to play Mozart K331 Trio Measure 11?
  • Did the Z8000 ever hit the home computer market?
  • How does Legendre transformation in classical mechanics relate to Adrien-Marie Legendre?
  • Alternative chalk board materials
  • QGIS 3.28: Set the "no data" colour to transparent for multiple rasters?
  • What comes first - apple in honey or pomegranate?

how to assign ip address to eth0 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 .

Stack Exchange Network

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

Super User is a question and answer site for computer enthusiasts and power users. 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.

Instantly assign static IP address in embedded Linux

Is there some basic Linux way to assign a static IP address without writing some files, just for the current session until reboot?

  • embedded-linux

Paul's user avatar

2 Answers 2

IIUC, you can do that with ifconfig tool. Most Linux -based systems come with ifconfig by default. Usage:

Arkadiusz Drabczyk's user avatar

Just for completeness: ifconfig has been superseded by ip . ip has more functionality, a cleaner syntax, and it's easier to parse the output in scripts.

Assuming you want to add a /24 address on eth0 , use:

will show the assigned addresses for all interfaces.

dirkt's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged linux networking ip-address embedded-linux ..

  • Featured on Meta
  • Our Design Vision for Stack Overflow and the Stack Exchange network

Hot Network Questions

  • Idiom for frustrating someone else's plans by taking what the other person wanted in the first place
  • Are there any good alternatives to firearms for 1920s aircrafts?
  • What comes first - apple in honey or pomegranate?
  • Why do people buy high dividend stock?
  • StarCraft II eating my RAM
  • What だってそうだろう means here?
  • Correct way to play Mozart K331 Trio Measure 11?
  • How to handle conversation between a druid and wild / tamed animals?
  • Golf the fast growing hierarchy
  • Question about number format for numbers between zero and one
  • Changing mono font with PDFLaTeX
  • Add two really big numbers
  • Be big more often
  • Meaning of "retiring" in "free admission with retiring donations"
  • Are all homotopy equivalences realized by fibrations over [0,1]?
  • Is electric field inside a conductor really always zero?
  • Why does Canada's superficial loss rule also include a clause for "30 days before the sale"?
  • Does query string case affect SEO?
  • How does Legendre transformation in classical mechanics relate to Adrien-Marie Legendre?
  • What order should my index's columns be for a SELECT a, b, MAX( c ) FROM d WHERE e = 1 GROUP BY a, b?
  • How can I pass a statistics exam that overly relies on memorizing formulas?
  • Method was removed after version 58.0: getSalesforceBaseUrl
  • Sci-fi story involving telescopic technology that could reach out into space and view the universe from remote locations
  • Does anyone know this skyline?

how to assign ip address to eth0 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 .

Select Your Language

Infrastructure and management.

  • Red Hat Enterprise Linux
  • Red Hat Satellite
  • Red Hat Subscription Management
  • Red Hat Insights
  • Red Hat Ansible Automation Platform

Cloud Computing

  • Red Hat OpenShift
  • Red Hat OpenStack Platform
  • Red Hat OpenShift Container Platform
  • Red Hat OpenShift Data Science
  • Red Hat OpenShift Dedicated
  • Red Hat Advanced Cluster Security for Kubernetes
  • Red Hat Advanced Cluster Management for Kubernetes
  • Red Hat Quay
  • OpenShift Dev Spaces
  • Red Hat OpenShift Service on AWS
  • Red Hat Gluster Storage
  • Red Hat Hyperconverged Infrastructure
  • Red Hat Ceph Storage
  • Red Hat OpenShift Data Foundation
  • Red Hat Runtimes
  • Red Hat JBoss Enterprise Application Platform
  • Red Hat Data Grid
  • Red Hat JBoss Web Server
  • Red Hat Single Sign On
  • Red Hat support for Spring Boot
  • Red Hat build of Node.js
  • Red Hat build of Quarkus

Integration and Automation

  • Red Hat Application Foundations
  • Red Hat Fuse
  • Red Hat AMQ
  • Red Hat 3scale API Management
  • Single-page

Language and Page Formatting Options

Red hat training.

A Red Hat training course is available for Red Hat Enterprise Linux

3.6. Configuring IP Networking with ip Commands

Assigning a static address using ip commands, configuring multiple addresses using ip commands.

Stack Exchange Network

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

Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 to display IP address of eth0 interface using a shell script?

How can I display the IP address shown on eth0 using a script ?

Jesse Nickles's user avatar

19 Answers 19

For the sake of providing another option, you could use the ip addr command this way to get the IP address:

  • ip addr show eth0 shows information about eth0
  • grep "inet\b" only shows the line that has the IPv4 address (if you wanted the IPv6 address, change it to "inet6\b" )
  • awk '{print $2}' prints on the second field, which has the ipaddress/mask, example 172.20.20.15/25
  • cut -d/ -f1 only takes the IP address portion.

In a script:

Alaa Ali's user avatar

  • this solution actually works! –  thang Nov 14, 2018 at 23:10
  • ip -4 ... and ip -6 ...! Thank you! –  TamusJRoyce May 22, 2019 at 18:12
  • ip addr show eth0 | grep -P "inet6?\b" | awk '{print $2}' | cut -d/ -f1 will print both IPv4 and IPv6. –  Artem Russakovskii Jun 4, 2020 at 8:14

Note: This answer is for older systems. If this does not work for you please consider other answers. This answer is not incorrect.

save this in a file and then run bash <filename>

being more accurate to get only number showing IP address:

Update : If this doesn't works for you, try the other answer

Update : For Ubuntu 18+, try: (don't forget to replace eth0 with interface you need the IP for. Thanks to @ignacio )

Alex Jones's user avatar

  • 4 of course this doesn't work in the latest ubuntu. the latest ifconfig returns "inet <ip>" instead of "inet addr <ip>" –  thang Nov 14, 2018 at 23:10
  • 2 you can just use grep "inet" –  Andrei Radulescu Nov 10, 2019 at 15:11
  • here is an updated solution for ifconfig version "net-tools 2.10-alpha" : ifconfig eth0 | grep "inet" | grep -v "inet6" | sed -e 's/^[[:space:]]*//' | cut -d ' ' -f 2 –  Maxime Ancelin Feb 13, 2020 at 9:03
  • 1 @MaximeAncelin you should add new answer for this –  Alex Jones Feb 13, 2020 at 9:57
  • 2 quick update for Ubuntu 18.04 : ifconfig wlan0 | grep "inet " | awk '{print $2}' –  ignacio Oct 28, 2020 at 16:55

Taken from https://stackoverflow.com/a/14910952/1695680

However that may return a local ip address (127.0.0.1), so you may have to use, and filter:

From hostname's manpages:

-i, --ip-address Display the network address(es) of the host name. Note that this works only if the host name can be resolved. Avoid using this option; use hostname --all-ip-addresses instead. -I, --all-ip-addresses Display all network addresses of the host. This option enumerates all configured addresses on all network inter‐faces. The loopback interface and IPv6 link-local addresses are omitted. Contrary to option -i, this option does not depend on name resolution. Do not make any assumptions about the order of the output.

Community's user avatar

  • 1 for the record, I like ip addr show label 'enp*' better, but I is annoying parse, something like ip addr show label 'enp*' | grep -oP inet\ \\S+ | cut -d' ' -f2 can work... how pretty –  ThorSummoner Nov 20, 2018 at 23:37
  • ip route | grep default | grep -oP 'dev \S+' | cut -d' ' -f 2 | xargs ip addr show dev | grep -oP 'inet6? \S+' –  ThorSummoner Apr 11, 2020 at 1:43

You should use ip (instead of ifconfig ) as it's current, maintained, and perhaps most importantly for scripting purposes, it produces a consistent & parsable output. Following are a few similar approaches:

If you want the IPv4 address for your Ethernet interface eth0 :

As a script:

will yield: 192.168.1.166/24 as its output

The output produced above is in CIDR notation. If CIDR notation isn't wanted, it can be stripped:

Another option that IMHO is "most elegant" gets the IPv4 address for whatever interface is used to connect to the specified remote host (8.8.8.8 in this case). Courtesy of @gatoatigrado in this answer :

Or, as a script:

will yield: 192.168.1.166 as its output

This works perfectly well on a host with a single interface, but more advantageously will also work on hosts with multiple interfaces and/or route specifications.

While ip would be my preferred approach, it's certainly not the only way to skin this cat. Here's another approach that uses hostname if you prefer something easier/more concise:

Or, if you want the IPv6 address:

will yield: 192.168.1.166 , and 2601:7c1:103:b27:352e:e151:c7d8:3379 as its answers ( assuming you have an IPv6 address assigned ).

Seamus's user avatar

@markus-lindberg 's response is my favourite. If you add -o -4 to ip's flags then you get a much more easily parsable (and consistent) output:

-o stands for --oneline , which is meant to help in exactly this kind of situations. The -4 is added to limit to the IPv4 address, which is what all the other responses imply.

Capt. Crunch's user avatar

  • 1 Love the ip flags. Using cut rather than advanced awk wizardry: ip -o -4 addr show eth0 scope global | awk '{print $4;}' | cut -d/ -f 1 –  Dawngerpony Dec 16, 2016 at 14:03
  • 1 @DuffJ it's probably down to a matter of personal taste. I "discovered" cut way after I learned about awk , and I like minimising the number of commands on my pipelines. Nice suggestion in any case. –  Capt. Crunch Dec 17, 2016 at 6:55
  • 1 I completely agree, Amos. Thanks for your solution! –  Dawngerpony Dec 19, 2016 at 12:34
  • 1 Very helpful. This should be the accepted answer, and this is not using the deprecated ifconfig which needs you to explicitly install net-tools in Ubuntu. –  Haris Jun 11, 2020 at 17:28

Here are some oneliners.....

split function in the above awk command splits the second column based on the delimiter : and stores the splitted value into an associative array a . So a[2] holds the value of the second part.

In basic sed , \(...\) called capturing group which is used to capture the characters. We could refer those captured characters through back-referencing. \([^[:space:]]\+\) captures any character but not space one or more times.

\K discards the previously matched characters from printing at the final and \S+ matches one or more non-space characters.

One or more non-space characters which are next to the inet addr: string are captured and finally we print those captured characters only.

Avinash Raj's user avatar

  • @edwardtorvalds added some explanation. I think this would be helpful for future readers. Feel free to ask any questions from the above commands... :) –  Avinash Raj Dec 12, 2014 at 8:07

This only use ip addr which is a replacement for ifconfig and awk combined with substitution (gsub).

Stop using too many processes for simple tasks

muru's user avatar

Just one more option that can be useful if you don't have awk (as it is the case in some embedded devices):

Fulvio Flaco's user avatar

Here's a good one, only uses grep as secondary command:

ip addr show eth0 | grep -oP 'inet \K\S[0-9.]+'

I don't see why you should use more commands than needed

Rick's user avatar

ifconfig eth0|grep 'inet '|awk '{print $2}'

Maksim Kostromin's user avatar

here's for IPv4 :

ip -f inet a|grep -oP "(?<=inet ).+(?=\/)"

here's for IPv4 & particular dev (eth0):

ip -f inet a show eth0|grep -oP "(?<=inet ).+(?=\/)"

ip -6 -o a|grep -oP "(?<=inet6 ).+(?=\/)"

XXL's user avatar

I suggest using a python library like netifaces that is specifically designed for this purpose.

To obtain the default network interface that is in use.

Sandeep's user avatar

this can be used with a normal user too.

Matheus Baldasso's user avatar

  • he ask for eth0, this version of your script could help (also show loopback tho) ip addr show | grep "inet " | cut -d '/' -f1 | cut -d ' ' -f6 –  TiloBunt Mar 25, 2017 at 17:01
  • This is pretty much the same answer as askubuntu.com/a/560466/367990 , just using cut twice instead of a combination of awk and cut to parse the output. Next time you should better check out all other answers first and ensure you don't post a duplicate solution. In this case here, I think it's arguable whether it's a duplicate or just similar, so please take it as a general hint. Thanks. –  Byte Commander ♦ Jul 7, 2017 at 19:49

in these days with multiples interfaces (eg if you use a docker) and naming interface by ETH is not anymore the norms

I use this command to extract the IP/Mask :

So whatever how many interfaces I'll have and whatever their name, GREP will only grab the first having the MULTICAST option.

I use this command to extract only the IP without the mask :

I use these command on different BDS & NIX it never fail ;)

JOduMonT's user avatar

  • If you're going to parse the output of ip , use the -o option. –  muru Oct 26, 2017 at 8:31

Yet another way (assuming you don't want a CIDR address and want IPv4 ):

  • Uses the ip command which is not deprecated
  • Uses only one command for filtering

htaccess's user avatar

This is the shortest way I could find:

ip -f inet addr show $1 | grep -Po 'inet \K[\d.]+'

Replace $1 with your network interface.

ip -f inet tells ip to only return values for the inet (ipv4) family.

grep -Po tells grep to interperate the next value as a perl-regex, and only print the matching values.

The regex \K[\d.]+ says "throw away everything up to this point (\K), and match as many numeric values followed by a dot in a row as possible". This will therefore only match the IP address and ignore everything after it, including the shortform \XX subnet mask.

In my script I'm using something like that:

It doesn't spawn any process.

derHugo's user avatar

If eth0 has multiple IPs and you are looking for a public one here is an example of ignoring the 2 most common internal IP address ranges.

This ignores 10.0.0.0/8 and 192.168.0.0/16 IPs.

Jeremy Cook's user avatar

Yes, you can do it like the other entries suggest, but you can also do it like a bauss:

The script is from my collection

Sample output A:

Sample output B:

Ярослав Рахматуллин's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged scripts ip interface ..

  • Featured on Meta
  • Our Design Vision for Stack Overflow and the Stack Exchange network
  • AI-generated content is not permitted on Ask Ubuntu

Hot Network Questions

  • Be big more often
  • Meaning of "retiring" in "free admission with retiring donations"
  • Why can one not form passive with “wissen/kennen”?
  • Does query string case affect SEO?
  • Why is there nearly no 1x road bikes?
  • Is electric field inside a conductor really always zero?
  • Spongy brakes in a 2004 Toyota corolla
  • Zener Transistor regulator cascaded into 3-pin IC regulator
  • Why isn't the penetrating depth of electromagnetic radiation consistent with its frequency?
  • Is "legalese" a thing in languages other than English?
  • Is there any jurisdiction where political views are a protected characteristic?
  • Is this duplo train track under too much tension?
  • How can I add a circle along the planes?
  • Is this possible to boot an OS from some kind of a file?
  • Why is the French embassy in Niger still considered an embassy?
  • How to describe the location (North, South, East and West) of country/city with respect to other country/city (in German language)
  • Difference between how a physicist and mathematician approach science?
  • How do you deal with movement inertia in an environment after a step?
  • What Does Gnosis Safe Contract's setup function return and why?
  • Why are hangars so high?
  • Intercepting a grappled Bite Swallow attack in place of an ally with Vigilant Guardian: What happens?
  • Did the Z8000 ever hit the home computer market?
  • Question about number format for numbers between zero and one
  • Getting a short string from a long one without spaces

how to assign ip address to eth0 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 .

Tecmint: Linux Howtos, Tutorials & Guides

A Beginner-Friendly Guide for Linux / Start Learning Linux Quickly...

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.

Previous article:

Next article:

Photo of author

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Related Posts

Linux /proc Filesystem

How to Use /proc File System to Monitor Your Linux System

Add and Remove Files in Tar Archive

How to Add, Delete and Update Files in Tar Archive in Linux

Find Disk Usage of Files in Linux

10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories

Create and Convert Linux File Systems

What are Ext2, Ext3 & Ext4? How to Create and Convert Linux File Systems

Linux Commandline Monitoring Tools

20 Command Line Tools to Monitor Linux Performance

Download Song from YouTube Video

YTP-DL: The Easiest Way to Download Songs from YouTube Videos

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

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

Save my name, email, and website in this browser for the next time I comment.

Amazon EC2 instance IP addressing

Amazon EC2 and Amazon VPC support both the IPv4 and IPv6 addressing protocols. By default, Amazon VPC uses the IPv4 addressing protocol; you can't disable this behavior. When you create a VPC, you must specify an IPv4 CIDR block (a range of private IPv4 addresses). You can optionally assign an IPv6 CIDR block to your VPC and assign IPv6 addresses from that block to instances in your subnets.

Private IPv4 addresses

Public ipv4 addresses, elastic ip addresses (ipv4), ipv6 addresses, work with the ipv4 addresses for your instances, work with the ipv6 addresses for your instances.

  • Multiple IP addresses

EC2 instance hostnames

A private IPv4 address is an IP address that's not reachable over the Internet. You can use private IPv4 addresses for communication between instances in the same VPC. For more information about the standards and specifications of private IPv4 addresses, see RFC 1918 . We allocate private IPv4 addresses to instances using DHCP.

You can create a VPC with a publicly routable CIDR block that falls outside of the private IPv4 address ranges specified in RFC 1918. However, for the purposes of this documentation, we refer to private IPv4 addresses (or 'private IP addresses') as the IP addresses that are within the IPv4 CIDR range of your VPC.

VPC subnets can be one of the following types:

IPv4-only subnets: You can only create resources in these subnets with IPv4 addresses assigned to them.

IPv6-only subnets: You can only create resources in these subnets with IPv6 addresses assigned to them.

IPv4 and IPv6 subnets: You can create resources in these subnets with either IPv4 or IPv6 addresses assigned to them.

When you launch an EC2 instance into an IPv4-only or dual stack (IPv4 and IPv6) subnet, the instance receives a primary private IP address from the IPv4 address range of the subnet. For more information, see IP addressing in the Amazon VPC User Guide . If you don't specify a primary private IP address when you launch the instance, we select an available IP address in the subnet's IPv4 range for you. Each instance has a default network interface (eth0) that is assigned the primary private IPv4 address. You can also specify additional private IPv4 addresses, known as secondary private IPv4 addresses . Unlike primary private IP addresses, secondary private IP addresses can be reassigned from one instance to another. For more information, see Multiple IP addresses .

A private IPv4 address, regardless of whether it is a primary or secondary address, remains associated with the network interface when the instance is stopped and started, or hibernated and started, and is released when the instance is terminated.

A public IP address is an IPv4 address that's reachable from the Internet. You can use public addresses for communication between your instances and the Internet.

When you launch an instance in a default VPC, we assign it a public IP address by default. When you launch an instance into a nondefault VPC, the subnet has an attribute that determines whether instances launched into that subnet receive a public IP address from the public IPv4 address pool. By default, we don't assign a public IP address to instances launched in a nondefault subnet.

You can control whether your instance receives a public IP address as follows:

Modifying the public IP addressing attribute of your subnet. For more information, see Modify the public IPv4 addressing attribute for your subnet in the Amazon VPC User Guide .

Enabling or disabling the public IP addressing feature during launch, which overrides the subnet's public IP addressing attribute. For more information, see Assign a public IPv4 address during instance launch .

A public IP address is assigned to your instance from Amazon's pool of public IPv4 addresses, and is not associated with your AWS account. When a public IP address is disassociated from your instance, it is released back into the public IPv4 address pool, and you cannot reuse it.

You cannot manually associate or disassociate a public IP (IPv4) address from your instance. Instead, in certain cases, we release the public IP address from your instance, or assign it a new one:

We release your instance's public IP address when it is stopped, hibernated, or terminated. Your stopped or hibernated instance receives a new public IP address when it is started.

We release your instance's public IP address when you associate an Elastic IP address with it. When you disassociate the Elastic IP address from your instance, it receives a new public IP address.

If the public IP address of your instance in a VPC has been released, it will not receive a new one if there is more than one network interface attached to your instance.

If your instance's public IP address is released while it has a secondary private IP address that is associated with an Elastic IP address, the instance does not receive a new public IP address.

If you require a persistent public IP address that can be associated to and from instances as you require, use an Elastic IP address instead.

If you use dynamic DNS to map an existing DNS name to a new instance's public IP address, it might take up to 24 hours for the IP address to propagate through the Internet. As a result, new instances might not receive traffic while terminated instances continue to receive requests. To solve this problem, use an Elastic IP address. You can allocate your own Elastic IP address, and associate it with your instance. For more information, see Elastic IP addresses .

Instances that access other instances through their public NAT IP address are charged for regional or Internet data transfer, depending on whether the instances are in the same Region.

An Elastic IP address is a public IPv4 address that you can allocate to your account. You can associate it to and disassociate it from instances as you require. It's allocated to your account until you choose to release it. For more information about Elastic IP addresses and how to use them, see Elastic IP addresses .

We do not support Elastic IP addresses for IPv6.

You can optionally associate an IPv6 CIDR block with your VPC and associate IPv6 CIDR blocks with your subnets. The IPv6 CIDR block for your VPC is automatically assigned from Amazon's pool of IPv6 addresses; you cannot choose the range yourself. For more information, see the following topics in the Amazon VPC User Guide :

IP addressing for your VPCs and subnets

Add an IPv6 CIDR block to your VPC

Add an IPv6 CIDR block to your subnet

IPv6 addresses are globally unique and can be configured to remain private or reachable over the Internet. Your instance receives an IPv6 address if an IPv6 CIDR block is associated with your VPC and subnet, and if one of the following is true:

Your subnet is configured to automatically assign an IPv6 address to an instance during launch. For more information, see Modify the IPv6 addressing attribute for your subnet .

You assign an IPv6 address to your instance during launch.

You assign an IPv6 address to the primary network interface of your instance after launch.

You assign an IPv6 address to a network interface in the same subnet, and attach the network interface to your instance after launch.

When your instance receives an IPv6 address during launch, the address is associated with the primary network interface (eth0) of the instance. You can disassociate the IPv6 address from the network interface.

An IPv6 address persists when you stop and start, or hibernate and start, your instance, and is released when you terminate your instance. You cannot reassign an IPv6 address while it's assigned to another network interface—you must first unassign it.

You can assign additional IPv6 addresses to your instance by assigning them to a network interface attached to your instance. The number of IPv6 addresses you can assign to a network interface and the number of network interfaces you can attach to an instance varies per instance type. For more information, see IP addresses per network interface per instance type .

You can assign a public IPv4 address to your instance when you launch it. You can view the IPv4 addresses for your instance in the console through either the Instances page or the Network Interfaces page.

View the IPv4 addresses

Assign a public ipv4 address during instance launch.

You can use the Amazon EC2 console to view the public and private IPv4 addresses of your instances. You can also determine the public IPv4 and private IPv4 addresses of your instance from within your instance by using instance metadata. For more information, see Instance metadata and user data .

The public IPv4 address is displayed as a property of the network interface in the console, but it's mapped to the primary private IPv4 address through NAT. Therefore, if you inspect the properties of your network interface on your instance, for example, through ifconfig (Linux) or ipconfig (Windows), the public IPv4 address is not displayed. To determine your instance's public IPv4 address from an instance, use instance metadata.

To view the IPv4 addresses for an instance using the console

Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ .

In the navigation pane, choose Instances and select your instance.

The following information is available on the Networking tab:

Public IPv4 address — The public IPv4 address. If you associated an Elastic IP address with the instance or the primary network interface, this is the Elastic IP address.

Private IPv4 addresses — The private IPv4 address.

Secondary private IPv4 addresses — Any secondary private IPv4 addresses.

Alternatively, under Network interfaces on the Networking tab, choose the interface ID for the primary network interface (for example, eni-123abc456def78901). The following information is available:

Private IPv4 address — The primary private IPv4 address.

To view the IPv4 addresses for an instance using the command line

You can use one of the following commands. For more information about these command line interfaces, see Access Amazon EC2 .

describe-instances (AWS CLI)

Get-EC2Instance (AWS Tools for Windows PowerShell).

To determine your instance's IPv4 addresses using instance metadata

Connect to your instance. For more information, see Connect to your Linux instance .

Use the following command to access the private IP address:

Use the following command to access the public IP address:

If an Elastic IP address is associated with the instance, the value returned is that of the Elastic IP address.

Each subnet has an attribute that determines whether instances launched into that subnet are assigned a public IP address. By default, nondefault subnets have this attribute set to false, and default subnets have this attribute set to true. When you launch an instance, a public IPv4 addressing feature is also available for you to control whether your instance is assigned a public IPv4 address; you can override the default behavior of the subnet's IP addressing attribute. The public IPv4 address is assigned from Amazon's pool of public IPv4 addresses, and is assigned to the network interface with the device index of eth0. This feature depends on certain conditions at the time you launch your instance.

Considerations

You can't manually disassociate the public IP address from your instance after launch. Instead, it's automatically released in certain cases, after which you cannot reuse it. For more information, see Public IPv4 addresses . If you require a persistent public IP address that you can associate or disassociate at will, assign an Elastic IP address to the instance after launch instead. For more information, see Elastic IP addresses .

You cannot auto-assign a public IP address if you specify more than one network interface. Additionally, you cannot override the subnet setting using the auto-assign public IP feature if you specify an existing network interface for eth0.

The public IP addressing feature is only available during launch. However, whether you assign a public IP address to your instance during launch or not, you can associate an Elastic IP address with your instance after it's launched. For more information, see Elastic IP addresses . You can also modify your subnet's public IPv4 addressing behavior. For more information, see Modify the public IPv4 addressing attribute for your subnet .

To assign a public IPv4 address during instance launch using the console

Follow the procedure to launch an instance , and when you configure Network Settings , choose the option to Auto-assign Public IP .

To enable or disable the public IP addressing feature using the command line

Use the --associate-public-ip-address or the --no-associate-public-ip-address option with the run-instances command (AWS CLI)

Use the -AssociatePublicIp parameter with the New-EC2Instance command (AWS Tools for Windows PowerShell)

You can view the IPv6 addresses assigned to your instance, assign a public IPv6 address to your instance, or unassign an IPv6 address from your instance. You can view these addresses in the console through either the Instances page or the Network Interfaces page.

View the IPv6 addresses

Assign an ipv6 address to an instance, unassign an ipv6 address from an instance.

You can use the Amazon EC2 console, AWS CLI, and instance metadata to view the IPv6 addresses for your instances.

To view the IPv6 addresses for an instance using the console

In the navigation pane, choose Instances .

Select the instance.

On the Networking tab, locate IPv6 addresses .

Alternatively, under Network interfaces on the Networking tab, choose the interface ID for the network interface (for example, eni-123abc456def78901). Locate IPv6 addresses .

To view the IPv6 addresses for an instance using the command line

To view the ipv6 addresses for an instance using instance metadata.

Use the following command to view the IPv6 address (you can get the MAC address from http://169.254.169.254/latest/meta-data/network/interfaces/macs/ ).

If your VPC and subnet have IPv6 CIDR blocks associated with them, you can assign an IPv6 address to your instance during or after launch. The IPv6 address is assigned from the IPv6 address range of the subnet, and is assigned to the network interface with the device index of eth0.

To assign an IPv6 address during instance launch

Follow the procedure to launch an instance , and when you configure Network Settings , choose the option to Auto-assign IPv6 IP .

To assign an IPv6 address after launch

Select your instance, and choose Actions , Networking , Manage IP addresses .

Expand the network interface. Under IPv6 addresses , choose Assign new IP address . Enter an IPv6 address from the range of the subnet or leave the field blank to let Amazon choose an IPv6 address for you.

Choose Save .

To assign an IPv6 address using the command line

Use the --ipv6-addresses option with the run-instances command (AWS CLI)

Use the Ipv6Addresses property for -NetworkInterface in the New-EC2Instance command (AWS Tools for Windows PowerShell)

assign-ipv6-addresses (AWS CLI)

Register-EC2Ipv6AddressList (AWS Tools for Windows PowerShell)

You can unassign an IPv6 address from an instance at any time.

To unassign an IPv6 address from an instance using the console

Expand the network interface. Under IPv6 addresses , choose Unassign next to the IPv6 address.

To unassign an IPv6 address from an instance using the command line

unassign-ipv6-addresses (AWS CLI)

Unregister-EC2Ipv6AddressList (AWS Tools for Windows PowerShell).

When you create an EC2 instance, AWS creates a hostname for that instance. For more information on the types of hostnames and how they're provisioned by AWS, see Amazon EC2 instance hostname types . Amazon provides a DNS server that resolves Amazon-provided hostnames to IPv4 and IPv6 addresses. The Amazon DNS server is located at the base of your VPC network range plus two. For more information, see DNS attributes for your VPC in the Amazon VPC User Guide .

Warning

To use the Amazon Web Services Documentation, Javascript must be enabled. Please refer to your browser's Help pages for instructions.

Thanks for letting us know we're doing a good job!

If you've got a moment, please tell us what we did right so we can do more of it.

Thanks for letting us know this page needs work. We're sorry we let you down.

If you've got a moment, please tell us how we can make the documentation better.

  • Stack Overflow Public questions & answers
  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Talent Build your employer brand
  • Advertising Reach developers & technologists worldwide
  • Labs The future of collective knowledge sharing
  • About the company

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

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

Static IP address on eth1 in linux

I need to set a static IP address on the eth1 interface after boot up. However, on bootup the device always has a different IP address than the one configured in the /etc/network/interfaces. This is a linux OS on beagle bone.

The ifconfig output is as follows

  • beagleboneblack

PVB's user avatar

  • Welcome to Stackoverflow. This question is not about programming, so it is off-topic for this site. That said, are you sure you are editing the right file for your linux distro? Not all linux flavors use /etc/network/interfaces , so tell us what version of linux you are using, it is important for people trying to reproduce your problem. –  Paulo Scardine Jun 24, 2017 at 0:59
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See What topics can I ask about here in the Help Center. Perhaps Super User or Unix & Linux Stack Exchange would be a better place to ask. –  jww Jun 24, 2017 at 20:29
  • I am using the following version root@beaglebone:/etc/network# cat /proc/version Linux version 4.4.54-ti-r93 (root@a4-imx6q-wandboard-2gb) (gcc version 4.9.2 (Debian 4.9.2-10) ) #1 SMP Fri Mar 17 13:08:22 UTC 2017 –  PVB Jun 26, 2017 at 18:20

I think you need to add network address, gateway and DNS settings also, look here . And then restart the server using below command.

mdasari's user avatar

  • Be careful answering questions like these. Some in the community feel answers should be downvoted, too. Also see Should one downvote answers to off-topic questions? –  jww Jun 24, 2017 at 20:29
  • Gosh.. I didn't know that. I am new to the community sorry about that. I will go through guidelines once. Thanks jww. –  mdasari Jun 24, 2017 at 23:15
  • I tried adding the network address and gateway and DNS settings. I am still getting the same results. The etc/network/interfaces file is as below auto eth1 iface eth1 inet static address 192.168.3.10 netmask 255.255.255.0 network 192.168.3.0 gateway 192.168.3.1 dns-nameservers 8.8.8.8 # Ethernet/RNDIS gadget (g_ether) # Used by: /opt/scripts/boot/autoconfigure_usb0.sh iface usb0 inet static address 192.168.7.2 netmask 255.255.0.0 network 192.168.7.0 gateway 192.168.7.1 –  PVB Jun 26, 2017 at 18:15

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 and acknowledge that you have read and understand our privacy policy and code of conduct .

Not the answer you're looking for? Browse other questions tagged linux networking beagleboneblack or ask your own question .

  • Featured on Meta
  • Our Design Vision for Stack Overflow and the Stack Exchange network
  • Temporary policy: Generative AI (e.g., ChatGPT) is banned
  • Call for volunteer reviewers for an updated search experience: OverflowAI Search
  • Discussions experiment launching on NLP Collective

Hot Network Questions

  • CAT: Cat Approved TUIs
  • Why are all eigen solvers iterative?
  • Does anyone know this skyline?
  • Geometry nodes, how to flat mesh islands on z axis
  • Are these lines by Thomas Nuce a translation and/or taken from a longer poem?
  • How does Legendre transformation in classical mechanics relate to Adrien-Marie Legendre?
  • StarCraft II eating my RAM
  • Could a planet orbiting a star have a habitable moon and this moon have its own moon orbiting it?
  • Is this duplo train track under too much tension?
  • How can I pass a statistics exam that overly relies on memorizing formulas?
  • Add two really big numbers
  • Correct way to play Mozart K331 Trio Measure 11?
  • Are all homotopy equivalences realized by fibrations over [0,1]?
  • Are there any good alternatives to firearms for 1920s aircrafts?
  • Parity and the Axiom of Choice
  • Is "legalese" a thing in languages other than English?
  • Why do people do a postdoc, rather than getting another PhD?
  • Poison ivy chess: Can the king get to safety?
  • Partition a random sequence composed of three numbers
  • Why do some US senators, like Joe Biden, Mitch McConnell, Dianne Feinstein, etc., last for so long in the Senate?
  • Young adult book series about kids who get different powers when they turn a certain age and their blood turns silver
  • What order should my index's columns be for a SELECT a, b, MAX( c ) FROM d WHERE e = 1 GROUP BY a, b?
  • How to handle conversation between a druid and wild / tamed animals?
  • Stellarium and the Taurids

how to assign ip address to eth0 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 .

How-To Geek

How to change your ip address from the command line in linux.

It's easy to change your IP address using a graphic interface, but did you know that Linux also lets you change your network card's IP address using a simple command from the command line?This trick should work on all Debian-based Linux distros, including Ubuntu.

It's easy to change your IP address using a graphic interface, but did you know that Linux also lets you change your network card's IP address using a simple command from the command line?

This trick should work on all Debian-based Linux distros, including Ubuntu. To get started, type

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:

sudo ifconfig eth0 192.168.0.1 netmask 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:

sudo route add default gw 192.168.0.253 eth0

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

IMAGES

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

    how to assign ip address to eth0 in linux

  2. How to Configure a Static IP Address on CentOS 8

    how to assign ip address to eth0 in linux

  3. Linux ip Command Examples

    how to assign ip address to eth0 in linux

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

    how to assign ip address to eth0 in linux

  5. Configuring an Additional IP Address on a Linux Server

    how to assign ip address to eth0 in linux

  6. Configuring an Additional IP Address on a Linux Server

    how to assign ip address to eth0 in linux

VIDEO

  1. way to config IP in Linux

  2. How to set multiple IP to one single network interface in Fedora or CentOS system

  3. How to Assign IP Address in your computer using CMD

  4. How to change ip address of linux

  5. IP address setup in Ubuntu through command line and Desktop graphical methods

  6. IP Addressing : Configure IP Addresses

COMMENTS

  1. How to configure eth0 manually?

    4 Answers Sorted by: 15 I am not sure what you exactly mean by your question. The real manual method has been described above, but since you write you don't have DHCP, I think you rather would like to know what to do to give your box a static IP address and assign this IP address at boot time automatically. Well, here is how:

  2. Linux ip Command with Examples

    The syntax for the ip command is as follows: ip [ OPTIONS ] OBJECT { COMMAND | help } OBJECT is the object type that you want to manage. The most frequently used objects (or subcommands) are: link ( l) - Display and modify network interfaces. address ( a) - Display and modify IP Addresses. route ( r) - Display and alter the routing table.

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

    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.

  4. ip

    Add a comment 2 Answers Sorted by: 42 If your dhcp is properly configured to give you an IP address, the command: dhclient eth0 -v should work. The option -v enable verbose log messages, it can be useful. If your eth0 is already up, before asking for a new IP address, try to deconfigure eth0.

  5. Linux ifconfig Command

    With the ifconfig command, you can assign an IP address and netmask to a network interface. Use the following syntax to assign the IP address and netmask:

  6. networking

    I have an extra IP address available to my server, and so I need to assign it in the interfaces file. At the moment, I've got this: auto lo iface lo inet loopback auto eth0 iface eth0 inet static address aaa.aaa.aaa.aaa netmask 255.255.254. gateway bbb.bbb.bbb.bbb dns-nameservers ccc.ccc.ccc.ccc ddd.ddd.ddd.ddd eee.eee.eee.eee dns-search vps-number.com

  7. Instantly assign static IP address in embedded Linux

    Just for completeness: ifconfig has been superseded by ip.ip has more functionality, a cleaner syntax, and it's easier to parse the output in scripts.. Assuming you want to add a /24 address on eth0, use:. ip addr add 192.168.100.100/24 dev eth0 Just. ip addr will show the assigned addresses for all interfaces.

  8. Understanding and Configuring Linux Network Interfaces

    In short, we assign a special IP address (127.0.0.1). Here's the format for the declaration of an interface: iface <interface> <address_family> <method> For example, we could declare an interface eth0 and get an IP address dynamically using DHCP: iface eth0 inet dhcp. To configure an interface statically, we follow these steps.

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

  10. 3.6. Configuring IP Networking with ip Commands

    The package name in Red Hat Enterprise Linux 7 is iproute. If necessary, you can check that the ip utility is installed by checking its version number as follows: ~]$ ip -V ip utility, iproute2-ss130716. The ip commands can be used to add and remove addresses and routes to interfaces in parallel with NetworkManager, which will preserve them and ...

  11. How to display IP address of eth0 interface using a shell script?

    19 Answers Sorted by: 50 For the sake of providing another option, you could use the ip addr command this way to get the IP address: ip addr show eth0 | grep "inet\b" | awk ' {print $2}' | cut -d/ -f1 ip addr show eth0 shows information about eth0

  12. linux

    Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. Questions asking for code must demonstrate a minimal understanding of the problem being solved.Include attempted solutions, why they didn't work, and ...

  13. How to Find out the IP address assigned to eth0 and display IP only

    You can use the ifconfig command or ip command with grep command and other filters to find out an IP address assigned to eth0 and display it on screen. nixCraft: Privacy First, Reader Supported nixCraft is a one-person operation. I create all the content myself, with no help from AI or ML. I keep the content accurate and up-to-date.

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

  15. Amazon EC2 instance IP addressing

    Connect to your instance. For more information, see Connect to your Linux instance. ... and is assigned to the network interface with the device index of eth0. To assign an IPv6 address during instance launch ... choose Assign new IP address. Enter an IPv6 address from the range of the subnet or leave the field blank to let Amazon choose an ...

  16. How To Change IP Address on Linux

    To change your IP address, use "nmcli" on the "device" section and specify that you want to "modify" the "ipv4.address" of your network card. $ nmcli device modify <interface_name> ipv4.address <ip_address>. When using the "nmcli device modify" command, your Network Manager will automatically create a new connection file in ...

  17. How to Use the ip Command on Linux

    Adding a Route Taken Route, Not Taken Root You can configure IP addresses, network interfaces, and routing rules on the fly with the Linux ip command. We'll show you how you can use this modern replacement of the classic (and now deprecated) ifconfig . How the ip Command Works

  18. How to Change IP Address in Linux

    sudo nano /etc/network/interfaces If your file read like the below, your IP address will be set by a DHCP client: auto eth0 iface eth0 inet dhcp To change the IP address as per our choice, we can modify this file to manually set the IP address. To set the IP address statically, for e.g. as 192.168.56.20, change the above entry to look as:

  19. Static IP address on eth1 in linux

    Teams. Q&A for work. Connect and share knowledge within a single location that is structured and easy to search. Learn more about Teams

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

    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.