Command in linux to get ip address

How to Find/Get your IP Address in Linux

Knowing the IP address of your device is important when troubleshooting network issues, setting up a new connection, or configuring a firewall.

IP Addresses can be classified into two categories, public and private. A public IP is an IP Address that is unique and can be accessed from the Internet. Private IP addresses are reserved for internal use within your private network without being directly exposed to the Internet. Furthermore, there are two types of IP addresses, IP version 4 (IPv4), and IP version 6 (IPv6).

This article explains several different methods of determining the public and private IP Addresses of a Linux system.

Find Your Private IP Address #

Private IP addresses are not routable over the Internet and are meant to work within the local network only. Typically, a private IP address is assigned to each device inside your local network by your router. This provides a unique IP address for all devices within the local network, such as your phone, laptop, smart TV, printer, media center, etc.

Devices on the local network are connecting to the Internet through NAT (network address translation).

The following IPv4 address ranges are reserved for the private networks:

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:

The output will look something like below. The private IP address is highlighted.

You can also use the following commands to display the private IP address:

Find Your Public IP Address #

A Public IP address is a globally routable IP address that is assigned to a network device, allowing it direct access to the Internet. They are assigned to the device by its ISP, and each device has a unique public IP address.

The public IP addresses are used by home routers, web servers, mail servers, and so on.

Determining the public IP address involves contacting a remote server over the HTTP/HTTPS or DNS protocol and obtaining the IP address from the remote server response.

On Desktop machines, the easiest way to find out your public IP address is to type “what is my ip” in your browser:

If you are on a headless Linux server or you want to assign the IP address to a shell script variable you can use command-line tools such as dig , curl and wget .

Most of the DNS providers, such as OpenDNS and Google allows you to query their servers and obtain your public IP address.

Читайте также:  How to apply patch linux

You can use any of the commands below to get your IP:

dig ANY +short @resolver2.opendns.com myip.opendns.com
dig ANY +short @resolver2.opendns.com myip.opendns.com
dig ANY +short @ns1-1.akamaitech.net ANY whoami.akamai.net

There are many online HTTP/HTTPS services that respond with your public IP address. Here are some of them:

curl -s https://checkip.amazonaws.com
wget -O - -q https://icanhazip.com/

If any of the commands above is not working, there may be a problem with the online service.

You can even create an alias in your ~/.bashrc or ~/.zshrc file, so you don’t have to type and remember a long command. For example, you can add the following alias:

alias pubip='dig ANY +short @resolver2.opendns.com myip.opendns.com' 

Now, whenever you need to find your public IP just type pubip in your terminal.

Conclusion #

We have shown you several different commands and online services that you can use to find out your private and public IP address.

If you have any questions or remarks, please leave a comment below.

Источник

How to Find or Check Your IP Address in Linux

An IP address is a codename assigned to a computer on a network. It works as a postal address, ensuring that network traffic is sent to the correct computer.

In this tutorial you will learn how to find your IP address using a Linux operating system.

Tutorial on how to find your IP address on Linux.

Find Your IP Address From the Command Line

There are a few different commands you can use to check your IP address. To run these commands, start by opening a terminal window/command line.

Using the hostname Command

One way to check your IP address from the command-line is by using the following command:

The system will display your internal IP address.

get ip address in linux terminal

Using the ip addr Command

Check your ip address with the ip addr command:

The system will scan your hardware, and display the status for each network adapter you have. Look for an entry that says link/ether. Below it, you should see one of the following:

inet6 fe80::a00:27ff:fe76:1e71/64

check ip address with ip addr command in linux

The entries will include one for a wired (Ethernet) adapter and a wireless (Wi-Fi) adapter. You may also have an entry for a virtual adapter. Generally, only one entry will have an IP address listed – that is the one you will want.

Note: The number after the slash – /24 and /64 – specifies the size of the network, and it helps with scanning and mapping network size.

Using the ifconfig Command

The third method to find your IP address involves using the ifconfig command. In the command line, enter the following:

The system will display all network connections – including connected, disconnected, and virtual. Look for the one labeled UP, BROADCAST, RUNNING, MULTICAST to find your IP address. This lists both IPv4 and IPv6 addresses.

Note: When you check your IP address, you may notice the term loopback. This refers to an IP address that returns traffic to the same computer. Usually, the loopback address is 127.0.0.1 . If you see that address listed, either you are looking at the wrong line, or you are not connected to the network.

Read phoenixNAP’s ultimate Linux IP command tutorial with 31 examples to learn more!

Finding Your IP Address in Linux With a GUI

If you are using a point-and-click interface to run your Linux system, you can check your IP address by following these steps:

Читайте также:  Копирование всего содержимого папки linux

1. Go to the Application menu and type Settings into the search bar.

2. Click on the Settings icon that appears among the results, as in the image below:

search for settings screenshot in ubuntu

3. Next, find the Network tab in the Settings Menu and click on the Advanced Wired Settings icon.

network settings for finding ip address

4. This opens a new pop-up window with details on wired settings. Here you can find both your IPv4 address and your IPv6 address.

check ip address in wired details

How to Find Public IP Address

To find your public IP address, reach out to an external website.

If you are using a browser, navigate to:

If you are using a command-line or terminal, use a retrieval command like curl or wget to display the external IP address:

wget -O - -q https://checkip.amazonaws.com

example of looking up the public ip

Note: Did you know that when you use curl to connect to an insecure website, the output responds with an error? To resolve it, visit our guide on making curl ignore certificates.

What is a Public/Private IP Address?

Each computer in a network is required to have its own IP address. If two systems have the same IP address, it will generate errors on the network. Most modern networks will detect the problem and prompt you to fix it. However, older networks might get confused, trying to route traffic to both computers.

Most systems will have two different IP addresses:

  • Private IP address: This is the address used on the network. Also, it is the one you will want to use for configuring routing tools. On smaller networks, the internal IP address typically starts with 192.168.x.x. It is dynamically assigned to your computer whenever you connect.
  • Public IP address: This is the IP address that registers on a website when you visit it. When you connect to a small network, your computer connects to a router using an internal IP address. That router, in turn, connects to a bigger network (like an Internet Service Provider), which has its own IP address system.

Note: Learn everything you need to know about public and private IP addresses in our article Public vs. Private IP Address.

Now you know how to find a private and public IP address in Linux using multiple methods.

Each option strikes a balance between speed and complexity. Now you have the flexibility to choose, if you only need your internal IP address, you can use the hostname method. If you need more detailed information, view our article on 31 Linux IP Commands with examples.

Источник

How to Find IP Address in Linux Command Line

How do I find out the IP address of in Linux ? It’s a common question for a number of Linux users. Here are multiple ways to get the IP of host system in Linux.

A Few years back, ifconfig was the favorite way to know IP address in Linux. Unfortunately, ifconfig command has been deprecated. If you try to use this command today, you are most likely to see the following error:

command not found: ifconfig

You may wonder how do I find my IP in Linux then? Let me show you that.

Display IP address in Linux

That’s it. That’s how you display the IP address of host system in Linux command line. You can use the same command to get the IP address via bash scripts as well.

Читайте также:  Astra linux установка драйвера wifi

Other ways to find the IP address of your system in Linux

There are more ways to check the IP address in Linux. Let me show you them as well.

Show IP address with hostname command

The hostname command usually displays the hostname of your system. It can also be used to display the IP address of the host:

It will simply display the IP address of the host in the terminal.

Display IP address with nmcli tool

Most Linux distributions come with a Network Manager tool. This tool has a command line interface called nmcli. You can use this nmcli tool to view a number of network configurations.

The IP address can be displayed with:

You should see the IP address in the output.

What about ifconfig?

Actually, you can still use ifconfig command. It is present in net-tools package. You can install it using the package manager of your system. However, use of net-tools is not encouraged so I suggest sticking with the ip command.

In Ubuntu-based distributions, you can install net-tools using this command:

sudo apt install net-tools

Now you can use the ifconfig command to display the IP address of your system.

The output will be like this:

lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 14855 bytes 3027297 (3.0 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 14855 bytes 3027297 (3.0 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 wlp58s0: flags=4163 mtu 1500 inet 192.168.0.106 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::bf14:21e3:4223:e5e4 prefixlen 64 scopeid 0x20 ether 9c:b6:d0:d0:fc:b5 txqueuelen 1000 (Ethernet) RX packets 88413 bytes 61851930 (61.8 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 56505 bytes 11409219 (11.4 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Again, ifconfig has been deprecated and should not be used.

Bonus Tip: Finding the public IP address of your system

What you saw so far was to display the private IP address of your system. What I mean is that if you use a network router, you are most probably behind a NAT.

The IP address of your system is a private one, used only for communicating with the devices on your sub-network. Any device outside your home/work network won’t be able to find you with this IP address. They need to now the IP address of your router. Your router recognizes your device and communicates via the private IP address.

How do you get your public IP address (IP address of your router)? You’ll have to utilize third party tools.

For example, you can use the host command with OpenDNS and get the public IP address:

host myip.opendns.com resolver1.opendns.com

The output should be similar to this:

Using domain server: Name: resolver1.opendns.com Address: 208.67.222.222#53 Aliases: myip.opendns.com has address 202.91.87.117 Host myip.opendns.com not found: 3(NXDOMAIN) Host myip.opendns.com not found: 3(NXDOMAIN)

I hope this quick tip helped you in finding the IP address of your system in Linux command line. You may also read about finding the gateway IP in Linux.

As always, feel free to provide your feedback and suggestion in the comment section below.

Источник

Оцените статью
Adblock
detector