Menu
Find Your IP Address Full Details in Linux

Find Your IP Address Full Details in Linux

IP addresses act as unique identifiers that allow devices to communicate with each other over a network or the internet. They come in two main forms:

  • IPv4 – The most common type, these consist of four octets separated by periods, such as 192.168.1.1. IPv4 provides approximately 4 billion unique addresses.
  • IPv6 – A newer format that solves the limited availability of IPv4 addresses. Written as eight groups of four hexadecimal digits separated by colons, like 2001:db8:85a3::8a2e:370:7334. IPv6 provides approximately 340 undecillion addresses.

Additionally, IP addresses fall into two categories depending on their purpose:

  • Public IP Addresses – Used to communicate over the public internet. These are globally unique addresses assigned by your Internet Service Provider. Your home router uses NAT to translate private addresses to a public one.
  • Private IP Addresses – Used for local networks not connected to the wider internet. Commonly start with 10., 172.16., or 192.168.. Multiple private networks can use these same ranges.

Now that you understand the very basics of what IP addresses are, let‘s go through the various ways to find them on a Linux system. We‘ll start with finding your public facing IP address

Discover Your Public IP Address from Linux

When connecting to the public internet, your computer will be assigned a public IP address. This allows traffic to be routed globally to your specific device.

Here are some handy one-liner methods to find your public IP from the Linux command line:

1. Use curl and ifconfig.me

One of the simplest ways is to use curl to request your IP from the ifconfig.me service:

$ curl ifconfig.me
203.0.113.1  

The ifconfig.me domain will return just your plain public IP address, nothing else.

2. Query ipinfo.io

Another option is the ipinfo.io API which returns your IP in JSON format:

$ curl ipinfo.io/ip
{"ip":"203.0.113.1"}

This gives you a bit more context compared to ifconfig.me.

3. Use dig and OpenDNS

The dig command can query DNS servers for your public IP as TXT records. Here we‘ll use OpenDNS:

$ dig +short myip.opendns.com @resolver1.opendns.com
"203.0.113.1"

4. Fetch from icanhazip.com

Similar to ifconfig.me, icanhazip.com is a simple domain that returns your public IP:

$ curl icanhazip.com 
203.0.113.1

5. Query ipify.org

Another clean API endpoint, ipify.org will return just your IP address:

$ curl -s https://api.ipify.org && echo
203.0.113.1

6. Use wget and ipecho.net

With wget we can fetch the plain text IP from ipecho.net:

$ wget -qO - http://ipecho.net/plain ; echo
203.0.113.1

7. Lookup Network Information with ip.pe

For a bit more info, ip.pe will return your public IP along with geographic location details:

$ curl ip.pe
203.0.113.1 / United States / North America

8. Query Google Public DNS

Google‘s public DNS server can also be used to find your public IP:

$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
"203.0.113.1" 

Those are some of the quickest and most common ways to find your public IP address from the  Linux command line. The ifconfig.me, icanhazip.com, and ipify.org websites provide simple, direct responses.

Now let‘s go over how to find the local private IP address of your Linux machine.

How to Find Your Private IP Address on Linux

For connecting to  routers, devices, and servers on your local network, you‘ll need your private IP address. This is an address in the 192.168.x.x172.16.x.x, or 10.x.x.x ranges assigned by your router‘s DHCP server.

Here are some handy commands for finding your private IP address in Linux:

1. Use the ip addr command

The best tool for this is the ip addr command which will list all network interfaces and IP address assignments:

$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP 
    inet 192.168.1.101/24 brd 192.168.1.255 scope global dynamic eth0
       valid_lft 84239sec preferred_lft 84239sec

We can see our local private IP is 192.168.1.101 on the eth0 interface.

2. Print IP addresses with hostname

The hostname command can print all assigned IP addresses:

$ hostname -I
192.168.1.101 127.0.1.1

3. Show interface information with ifconfig

The old school ifconfig command is still handy for displaying interface IP addresses:

$ ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.101  netmask 255.255.255.0  broadcast 192.168.1.255

4. View routing table data with ip route

The ip route command shows the routing table which contains interface IP address info:

$ ip route show
default via 192.168.1.1 dev eth0 proto dhcp metric 100  
169.254.0.0/16 dev eth0 scope link metric 1000
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.101 metric 100 

5. Use nmcli to show NetworkManager details

For NetworkManager connections, nmcli provides a detailed status view including your IP:

$ nmcli device show eth0
GENERAL.DEVICE:                         eth0
GENERAL.TYPE:                           ethernet
...
IP4.ADDRESS[1]:                         192.168.1.101/24
...

Those are some of the most common options for finding your private IP address on a Linux machine. The ip addr and ifconfig commands are especially useful.

Now that you know how to find your assigned public and private IP addresses, let‘s go over the steps for changing or setting a static IP on Linux.

Changing or Setting a Static IP Address in Linux

In many cases, you‘ll want to set a static IP address instead of using a dynamic one assigned by DHCP. This gives you a permanent address that won‘t change. Here‘s how to configure a static IP in Linux:

1. Use nmcli to modify NetworkManager connections

For NetworkManager profiles, you can use nmcli to modify the IP method and address:

$ sudo nmcli con mod eth0 ipv4.method manual ipv4.addr "192.168.1.5/24"

You‘ll also need to configure the DNS servers:

$ sudo nmcli con mod eth0 ipv4.dns "8.8.8.8,1.1.1.1"

2. Edit Netplan YAML configuration

If your network is configured using Netplan, edit the .yaml file in /etc/netplan:

network:
  version: 2
  ethernets:
    eth0:
      addresses: 
        - 192.168.1.5/24
      gateway4: 192.168.1.1  
      nameservers:
        addresses:
          - 1.1.1.1
          - 8.8.8.8

3. Configure interface in /etc/network/interfaces

For older ifupdown style configs, edit /etc/network/interfaces:

auto eth0
iface eth0 inet static
    address 192.168.1.5
    netmask 255.255.255.0
    gateway 192.168.1.1 
    dns-nameservers 1.1.1.1 8.8.8.8

After making IP address changes, you‘ll need to restart networking or reboot your system for them to take effect.

Verifying with ip addr show will display your new static IP address.

Some IP Address Configuration Tips

Here are some additional tips when modifying IP address settings on Linux:

  • Use -I flag on shutdown/reboot to prevent interface restart: shutdown -r -I +10
  • Check the arp table with arp -a to see your IP/MAC mapping
  • For cloud servers, assign IPs in the dashboard not the OS
  • Label interfaces in /etc/udev/rules.d/70-persistent-net.rules
  • For CentOS/RHEL use nmcli, nmtui or setup via /etc/sysconfig/network-scripts

And those are the basics of changing your IP address to a static one in Linux. The exact method depends on your network configuration, but nmcli and Netplan are most common these days.

Now that you know how to find your IP address and set a static one, let‘s go over some general IP address troubleshooting tips.

IP Address Troubleshooting Tips and Tricks

Dealing with network connectivity issues? Here are some handy troubleshooting tips related to IP addresses in  Linux:

  • Restart networking – Quick way to refresh if configs changed.
  • Renew DHCP lease – Requests new IP if expired. sudo dhclient -r && dhclient eth0
  • Flushing DNS – Clear cache if name resolutions fail. sudo systemd-resolve --flush-caches
  • Ping test – Confirm reachability of domains and IPs. ping 8.8.8.8
  • Tracepath – View  route and identify network issues. tracepath google.com
  • Change cables – Swap Ethernet cables to eliminate as source.
  • Disable IPV6 – Try disabling IPv6 in router if connectivity problems.
  • Verify NIC driver – Ensure using right driver for network interface card.
  • Check firewall rules – Make sure no IP blocks or port blocks.
  • Inspect DHCP config – Ensure DHCP server issuing expected IP range.
  • Analyze traffic – Use tcpdump or Wireshark to inspect network packets.
  • Compare configurations – Review running config vs startup config for issues.

Hopefully some of these tips will assist if you ever need to troubleshoot IP connectivity problems on Linux!

Now let‘s recap some key takeaways about IP addresses in Linux.

Quick IP Address Recap and Summary

Finding your IP address on Linux is easy using the various commands we‘ve covered:

  • Use curl and web APIs to find your public IP address
  • Use ip addr, ifconfig, nmcli or hostname to find your private IP
  • Modify IP addresses with nmcli, Netplan, or ifconfig as needed
  • Restart networking for IP address changes to take effect
  • Troubleshoot connectivity with tools like ping, tracepath, tcpdump

Information Gathering in Cyber Security

Overview

In the ever-evolving landscape of cybersecurity, staying one step ahead of potential threats is crucial. One fundamental aspect of this proactive approach is information gathering. Cybersecurity professionals employ various techniques to gather information about potential vulnerabilities, attack surfaces, and potential adversaries. These techniques can be broadly categorized into active and passive information gathering.

In this article, we are going to discuss details about what is active and passive information gathering.

What is Information Gathering?

Information gathering is also known as reconnaissance. The answer to the question what is information gathering is, it is the first phase of a cyberattack, where attackers collect data about their target. This data can include information about the target’s network architecture, system configurations, employee details, and potential vulnerabilities. In the hands of malicious actors, this information can be a precursor to a successful cyberattack. However, in the realm of cybersecurity, information gathering serves a noble purpose – to identify and address weaknesses in an organization’s security posture before attackers can exploit them.

Posture before refers to assessing and strengthening an organization’s security measures proactively, anticipating and addressing vulnerabilities before potential exploitation by attackers.

The first stage in any professional penetration test is cyber reconnaissance. Getting as much information as you can on the target is the aim of this phase. Technical details on its systems and network structure are included in this. However, it also contains data on the company and its personnel that could be helpful later on in the penetration test. Your chances of success in the following stages of the penetration test increase with the amount of information you obtain during the reconnaissance phase. Active information gathering and passive information gathering are the two forms of cyber reconnaissance.

What is Active Information Gathering?

Active information gathering in the context of information gathering in cybersecurity refers to a set of techniques and methods used to collect data and information about a target system, network, or organization by directly interacting with it.

This active approach involves sending requests or probes to the target to elicit responses and gain insights into its configuration, vulnerabilities, and potential weaknesses. Active information gathering techniques are typically conducted with the goal of assessing the security of a system or network and identifying vulnerabilities.

Key components and techniques involved in active information gathering may include:

  • Port Scanning:
    Port scanning tools like Nmap are commonly used to identify open ports and services running on a target system. Knowing which ports are open can provide insights into potential entry points for attackers or areas that require security hardening.
  • Vulnerability Scanning:
    Vulnerability scanners, such as Nessus or OpenVAS, actively search for known vulnerabilities in the target system or network. These tools attempt to exploit known weaknesses to assess the system’s security posture.
  • DNS Enumeration:
    Active information gathering may involve querying the Domain Name System (DNS) to discover information about a target’s domain names, subdomains, and associated IP addresses.
  • Banner Grabbing:
    Banner grabbing involves connecting to network services, such as web servers, and retrieving information from banners or headers that disclose details about the software and versions in use.
  • Brute Force Attacks:
    Brute force attacks actively attempt to guess login credentials by systematically trying various combinations of usernames and passwords. This is a common technique used in active reconnaissance to gain unauthorized access to systems.
  • Active Scanning and Ping Sweeps:
    These techniques involve sending ICMP echo requests (ping) or other network probes to determine the online/offline status of target hosts and devices.
  • Social Engineering and Phishing:
    While not technically network-based, social engineering and phishing attacks can be considered active information gathering methods. They rely on manipulating individuals to divulge sensitive information.

What is PassiveInformation Gathering?

Passive information gathering, in the context of information gathering in cybersecurity, refers to the collection of data and information about a target system, network, or organization without directly interacting with the target.

Unlike active information gathering, which involves making deliberate queries or requests to the target to obtain specific information, passive techniques rely on the observation of publicly available data, information that is inadvertently leaked, or network traffic monitoring.

Key components and techniques involved in passive information gathering may include:

  • Open-Source Intelligence (OSINT):
    Passive reconnaissance often begins with OSINT, which involves collecting publicly available information from various sources, such as websites, social media, public databases, and online forums. This can include information about an organization’s employees, contact details, software versions, and other details.
  • Network Traffic Analysis:
    Passive techniques may involve monitoring network traffic, such as network packet captures or log analysis, to gather information about the target’s infrastructure, devices, and services.
  • Search Engine Queries:
    Using search engines, passive information gathering can include conducting queries to find sensitive or confidential information accidentally exposed on the internet, like unsecured directories, login pages, or documents.
  • Passive DNS Analysis:
    Passive DNS analysis involves reviewing historical DNS data to understand domain name resolutions and track the evolution of a target’s online presence. This can provide insights into changes and associations.
  • Passive Social Engineering:
    This technique doesn’t involve direct interaction with individuals but rather relies on the information willingly shared by employees or users on social media or public platforms.
  • Wi-Fi Network Scanning:
    Passive scanning of Wi-Fi networks can help identify network names (SSIDs), encryption methods, and potentially open networks in the vicinity, revealing potential security risks.

Key difference Between Active and Passive Information Gathering

The key differences between active and passive information gathering in cybersecurity can be summarized as follows:

1. Interactivity:

  • Active Information Gathering:
    Involves direct interaction with the target, such as sending queries, probes, or requests to obtain information.
  • Passive Information Gathering:
    Does not involve direct interaction with the target; information is collected without engaging the target’s systems.

2. Visibility:

  • Active Information Gathering:
    More likely to be detected by the target, as it actively probes the target’s systems, potentially raising security alarms.
  • Passive Information Gathering:
    Less likely to be noticed by the target, as it involves observing and collecting publicly available information or monitoring network traffic discreetly.

3. Timing:

  • Active Information Gathering:
    Provides real-time data but may alert the target to potential threats, making it a quicker but riskier approach.
  • Passive Information Gathering:
    Generally slower, as it relies on observing and collecting information over time, but it is less likely to raise alarms.

3. Legality and Ethical Considerations:

  • Active Information Gathering:
    Can be legally complex and ethically sensitive, particularly when performed without proper authorization. Unauthorized or malicious use is often illegal.
  • Passive Information Gathering:
    Tends to be more legally and ethically sound since it typically involves collecting publicly available information or data inadvertently exposed by the target.

3. Purpose:

  • Active Information Gathering:
    Commonly used for security assessments, penetration testing, and offensive security to identify vulnerabilities and weaknesses.
  • Passive Information Gathering:
    Often used for reconnaissance, OSINT, and defensive security to gain insights into a target’s digital footprint and minimize information leakage.

Differences between Active and Passive Information Gathering

Active Information Gathering

  • Active techniques are often used for vulnerability assessments and penetration testing to identify and exploit weaknesses in a system’s security.
  • Ethical hackers and security professionals use active methods to assess the real-time security posture of a target system or network.
  • Active techniques are suited for quickly identifying immediate threats or vulnerabilities, making them valuable for responding to known issues promptly.
  • Active information gathering requires explicit authorization and is typically performed under controlled conditions, ensuring that it adheres to legal and ethical standards.

Passive Information Gathering

  • Passive techniques are commonly used for reconnaissance, open-source intelligence (OSINT) collection, and understanding the target’s digital footprint.
  • Passive techniques can help in assessing long-term risks and trends by discreetly observing target activities over time.
  • Passive methods are ideal when avoiding detection or alerting the target is a priority, as they involve discreet data collection without direct interaction.
  • Passive information gathering is often used for ethical and legal research, such as OSINT collection for threat intelligence, competitive analysis, or compliance.

Conclusion

  • Information gathering is the initial step in securing systems, allowing organizations to identify vulnerabilities before attackers exploit them.
  • Active and passive information gathering techniques offer distinct advantages and are chosen based on specific objectives and ethical considerations.
  • Adherence to legal and ethical guidelines is paramount to ensure responsible and lawful information gathering.
  • Combining active and passive techniques provides a more comprehensive view of an organization’s security posture and digital footprint.
  • Information gathering is an ongoing process, as the threat landscape evolves, and organizations need to adapt to emerging risks.
  • Collected data serves as strategic intelligence for threat mitigation, competitive analysis, and compliance with regulations.