Determine ip address linux

Как узнать IP адрес, используя командную строку Linux

Определить IP адрес в Linux

Раньше для просмотра текущих сетевых интерфейсов и их параметров (включая IP-адреса), использовалась команда ifconfig. Но она уже несколько лет как устарела, и в современных дистрибутивах Linux не поддерживается.

Вместо ifconfig рекомендуется использовать команду ip

Определяем IP-адрес командой ip

Чтобы определить IP-адрес вашего сетевого интерфейса можно использовать команду ip address (или эквивалентный вызов ip addr или просто ip a ).

ip address 1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: enp2s0: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:24:1d:83:da:25 brd ff:ff:ff:ff:ff:ff inet 192.168.2.2/24 brd 192.168.2.255 scope global dynamic noprefixroute enp2s0 valid_lft 76434sec preferred_lft 76434sec inet6 fe80::1f6e:e0e4:27d1:e643/64 scope link noprefixroute valid_lft forever preferred_lft forever 

Команда ip address Linux

В результате выполнения команды на экран будет выведен список текущих сетевых интерфейсов и их параметры. Первый интерфейс в списке обычно lo — это loopback интерфейс (нас он сейчас не интересует). Нас интересует Ethernet-интерфейс или WiFi-интерфейс (в зависимости от того, какое у вас подключение).

Ethernet интерфейсы обычно имеют имена вида enp2s0 или eth0, а WiFi-интерфейсы имеют имена вида wlp2s0 или wlan0 (цифры в названии могут отличаться).

Найдите интересующий вас интерфейс в списке. Его IP-адрес выводится на строке inet ..

Читайте также:  Публичный ip адрес linux

В нашем примере это inet 192.168.2.2/24 . 192.168.2.2 — это IP-адрес. 24 — это маска подсети, соответствующая маске 255.255.255.0.

Определяем IP-адрес командой hostname

Воспользуемся командой hostname , чтобы вывести IP-адрес. Используем ключ -I

Команда выводит все сетевые адреса хоста (системы), кроме loopback интерфейса. Если у вас всего одно сетевое соединение, то, скорее всего, будет выведен один IP-адрес.

Через графическую утилиту

Хотя эта заметка рассматривает способы определения IP-адреса через командную строку, иногда проще посмотреть текущий IP-адрес через графические программы. В Ubuntu 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.

Читайте также:  Linux boot no swap

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:

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.

Читайте также:  Linux add keyboard language

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.

Источник

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