Know local ip linux

How to Check IP Address on Linux using Command Line

As a Linux user, it’s often necessary to check your computer’s IP address, either for system troubleshooting or network configuration. The IP address, or Internet Protocol address, is a numerical label assigned to each device participating in a computer network. It serves two main functions: identifying the host or network interface and providing the location of the host in the network.

In Linux, there are various methods to retrieve this information, but this article will focus on using the command line interface (CLI), the most powerful and versatile tool at your disposal. By the end of this article, you’ll have learned how to use commands like ifconfig, ip, and hostname to reveal your computer’s IP address.

Understanding IP Addresses

Before we delve into the practical aspect, let’s understand what an IP address is. There are two versions of IP addresses in use today – IPv4 and IPv6. IPv4 is a numerical address like 192.168.0.1, and IPv6 is a more complex alphanumeric address like 2001:0db8:85a3:0000:0000:8a2e:0370:7334. Both serve the same purpose, to uniquely identify a device on a network, but IPv6 was introduced to deal with the long-anticipated problem of IPv4 address exhaustion.

The ifconfig Command

The ifconfig (interface configuration) command in Linux is used to display or configure a network interface. Although this command has been deprecated in favor of the ip command, it is still widely used and you’ll find it present in most systems.

To display your IP address using ifconfig, open your terminal and type the following:

This command will display the details of all network interfaces on your system. The ‘inet’ entry refers to your IPv4 address, and ‘inet6’ refers to your IPv6 address.

Identifying Your IP Address on Linux

  • Read: bash ifconfig: command not found on CentOS/RHEL 7

The ip Command

The ip command is a more powerful and modern replacement for ifconfig. It can perform several other tasks that ifconfig can’t.

To display your IP address using the ip command, type the following in your terminal:

Again, ‘inet’ refers to the IPv4 address and ‘inet6’ to the IPv6 address.

Unlocking Linux: Techniques to Determine Your IP Address

The hostname Command

The hostname command is used to display the system’s DNS name, and the -I option will display the IP address of your network interfaces.

To use this command, type the following in your terminal:

Читайте также:  Red hat enterprise linux курсы

This command will display all the network IP addresses assigned to your system.

A Comprehensive Guide to Finding Your IP Address

Getting the Public IP Address

While the aforementioned commands provide information about your private IP address, which is used within your local network, there may be occasions where you need to know your public IP address. This is the address that your Internet Service Provider (ISP) assigns to you, and it’s what the outside world sees when you’re connecting to websites and services on the internet.

In Linux, there’s no built-in command to retrieve the public IP address directly from the command line interface, but you can leverage some external services like dig command with OpenDNS, wget or curl with ifconfig.me service.

Using dig with OpenDNS

The dig command is a tool for querying DNS nameservers for information about host addresses, mail exchanges, nameservers, and related information. To use dig to find your public IP address, type the following in your terminal:

dig +short myip.opendns.com @resolver1.opendns.com 

This command tells dig to query the special address myip.opendns.com on the DNS server resolver1.opendns.com. The DNS server will return your public IP address.

Using wget or curl with ifconfig.me service

ifconfig.me is a web service that returns your public IP address. You can access it using either wget or curl.

Both commands will retrieve your public IP address from the ifconfig.me web service.

Conclusion

Understanding how to find your IP address in Linux is a crucial skill for managing and troubleshooting your system and network. Whether you’re a system administrator, a developer, or an enthusiastic Linux user, the command line offers powerful tools for you to unlock the full potential of your Linux system.

Remember, the Linux command line is a powerful tool, but with great power comes great responsibility. Always ensure you understand the commands you are running and the potential impact they may have on your system.

These are just a few of the commands available in Linux for working with IP addresses. As you delve deeper into the world of Linux, you’ll discover many more commands and options that can help you master your system and network.

Источник

How to find your IP address in Linux

Satellite in a field

We all use the Internet Protocol (IP) daily, whether we’re aware of it or not. For instance, any time you type a website name or a search term into your web browser, it looks up the IP address of that URL (or of a search engine) and then loads the website.

Let’s divide IP addresses into two categories: private and public. Private IP addresses are the ones your WiFi box (and company intranet) provide. They are in the range of 10.x.x.x, 172.16.x.x-172.31.x.x, and 192.168.x.x, where x=0 to 255. Public IP addresses, as the name suggests, are «public» and you can reach them from anywhere in the world. Every website has a unique IP address that can be reached by anyone and from anywhere; that is considered a public IP address.

Читайте также:  Linux mint установить шрифты

Furthermore, there are two types of IP addresses: IPv4 and IPv6.

IPv4 addresses have the format x.x.x.x, where x=0 to 255. There are 2 ^32 (approximately 4 billion) possible IPv4 addresses.

IPv6 addresses have a more complex format using hex numbers. The total number of bits is 128, which means there are 2 ^128 —340 undecillion!—possible IPv6 addresses. IPv6 was introduced to tackle the foreseeable exhaustion of IPv4 addresses in the near future.

As a network engineer, I recommend not sharing your machine’s public IP address with anyone. Your WiFi router has a public IP, which is the WAN (wide-area network) IP address, and it will be the same for any device connected to that WiFi. All the devices connected to the same WiFi have private IP addresses locally identified by the range provided above. For example, my laptop is connected with the IP address 192.168.0.5, and my phone is connected with 192.168.0.8. These are private IP addresses, but both would have the same public IP address.

The following commands will get you the IP address list to find public IP addresses for your machine:

  1. curl ifconfig.me
  2. curl -4/-6 icanhazip.com
  3. curl ipinfo.io/ip
  4. curl api.ipify.org
  5. curl checkip.dyndns.org
  6. dig +short myip.opendns.com @resolver1.opendns.com
  7. host myip.opendns.com resolver1.opendns.com
  8. curl ident.me
  9. curl bot.whatismyipaddress.com
  10. curl ipecho.net/plain

The following commands will get you the private IP address of your interfaces:

  1. ifconfig -a
  2. ip addr (ip a)
  3. hostname -I | awk »
  4. ip route get 1.2.3.4 | awk »
  5. (Fedora) Wifi-Settings→ click the setting icon next to the Wifi name that you are connected to → Ipv4 and Ipv6 both can be seen
  6. nmcli -p device show

Note: Some utilities need to be installed on your system based on the Linux distro you are using. Also, some of the noted commands use a third-party website to get the IP

Finding your IP address in the GNOME desktop

If you’re using Linux, you can find your IP address using some basic desktop utilities. First, go to your Activities screen and type Network (for a wired connection) or Wi-Fi (for wireless).

Use GNOME activities to locate your Network or Wi-Fi settings

In the Networks settings window, click the Gear icon next to the network you’re on.

Click the gear icon next to the Network you are on

Your IP address is listed in the Network profile.

IP addresses are provided in your Network profile

In this example screenshot, my IPv4 address is 10.1.1.2 and the gateway is 10.1.1.1.

Public and private IP addresses

To understand the significance of public and private IP addresses, let’s have a look at a concept called NAT (Network Address Translation) and PAT (Port Address Translation).

Private addresses are used in Local Area Networks (LAN). They are bound to a specific network.

Читайте также:  Установить pip linux centos

Public addresses are necessary for establishing external connectivity to other networks, most notably the «Worldwide Web» (www) of the Internet.

NAT is a translation of a private IP to a public one, and consists of three major types: static, dynamic, and PAT. In static NAT, one private IP is mapped to one public IP. A common example ru ydco is a firewall. In dynamic NAT, a private IP address is mapped to a public IP but from a pool of public IP addresses.

With a total of 2^32 IPv4 addresses, out of which approximately just 3.7 billion are public addresses, there are literally more people and devices than there are IP addresses. And yet we haven’t run out of addresses. That’s because of a concept called PAT, which allows for a single public IP address to be translated from multiple (generally all) private IP addresses using port numbers. Here, instead of assigning a public address to each device, a single public address is allocated to the external side, and private addresses are assigned to each device within the internal network. PAT is most widely used in residential wireless routers, which we use to connect to the Internet.

Private Ipv4 addresses

  • Local addresses are only used within an internal network.
  • The range is 10.x.x.x, 172.16.x.x-172.31.x.x, and 192.168.x.x, (x is a number from 0 to 255).
  • Used in Local Area Networks (LAN).
  • Not globally reachable, and cannot be searched globally.
  • Not unique: the same private IP can be used in two different networks.
  • Each router comes with a private IP address, which multiple devices can connect to. Users don’t need to pay extra to obtain a private address.
  • Some example private IP addresses: 10.0.0.4, 172.16.4.5, 192.168.9.8

Public Ipv4 addresses

  • Public addresses are used to connect to external networks.
  • Ranges from 0.0.0.0 to 255.255.255.255, except for private IP addresses and few unusable or reserved IPs.
  • Used in connecting to the Internet.
  • Globally reachable and can be searched. These are often used to determine geolocation.
  • Unique across all of the Internet.
  • A private address costs money because they are unique, limited, and accessible from the Internet. Each website has a domain name mapped to a public IP. For example, the public IP address for opensource.com is 54.204.39.132

Finding your way with IP

An IP address is the most direct route to a computer over a network. There are other systems, such as DNS and Avahi, to help route one computer to another, but when those are unavailable or undesired for any reason, the IP protocol is what you use. Now you understand why, and more importantly, how to find your own.

Editor’s note: This article was originally published in May 2018 and has been updated.

Источник

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