How to find my IP address on Ubuntu Linux

Published November 5, 2024
How to find my IP address on Ubuntu Linux
Cheap Dedicated Server

How to find my IP address on Ubuntu Linux


 

 

Essential Commands for Network Management in Linux: The Linux ‘ipconfig’ Alternative

For those new to Linux, one of the first challenges is managing network configurations without the familiar Windows ipconfig command. In Linux, networking is managed through different commands, each providing detailed insights into IP addresses, network interfaces, routing tables, and more. Let’s dive into some of the essential network management commands for Linux, their uses, and examples to help you navigate your network setup with ease.

1. ifconfig – The Classic Network Interface Command

ifconfig is the original network interface configuration tool on Unix-like systems. Although it’s gradually being replaced by the ip command, many distributions still support it. It provides information about network interfaces, IP addresses, and network statistics.

Basic Syntax:
Basic Syntax   

 
ifconfig

Usage Example:

 
ifconfig eth0

This command shows the IP address, broadcast address, and subnet mask for the eth0 interface. Note that some modern distributions may require you to install net-tools to use ifconfig.

2. ip – The Modern Alternative to ifconfig

The ip command has become the preferred tool for managing IP configurations in Linux, replacing ifconfig. It offers extended functionality and is more versatile, covering everything from IP addresses to routing and more.

Basic Syntax:

 
ip [command] [options]

Usage Examples:

  • To view all network interfaces and their configurations:
     
    ip addr show

  • To display the configuration of a specific interface (e.g., eth0):
     
    ip addr show eth0

  • To assign an IP address to an interface:
    To assign an IP address to an interface
     
    sudo ip addr add 192.168.1.10/24 dev eth0

  • To bring an interface up or down:
    To bring an interface up or down
     
    sudo ip link set eth0 up

    sudo ip link set eth0 down

3. nmcli – NetworkManager’s Command-Line Interface

For distributions using NetworkManager (common in desktop environments), nmcli is a useful command for managing network connections. It allows you to manage wireless networks, configure connections, and gather connection information directly from the terminal.

Basic Syntax:

 
nmcli [command] [options]

Usage Examples:

  • To list all available network interfaces and their states:
     
    nmcli device status

  • To connect to a Wi-Fi network:
    To connect to a Wi-Fi network
     
    nmcli device wifi connect "SSID_NAME" password "PASSWORD"

  • To disconnect a network:
     
    nmcli device disconnect iface_name

4. ping – Test Network Connectivity

The ping command is essential for diagnosing network issues, as it checks the reachability of a host on an IP network. It’s a quick way to verify if a device is online and determine network latency.

Usage Example:

 
ping google.com

This sends packets to Google’s servers and reports on how long it takes for a response, showing if there’s packet loss or latency.

5. traceroute – Trace the Route to a Destination

traceroute is useful for diagnosing network routing issues. It shows the path packets take from your system to a target address, which can help identify bottlenecks or failed nodes along the way.

Usage Example:

 
traceroute google.com

If traceroute isn’t installed, you can usually install it with:

 
sudo apt install traceroute

6. netstat – Network Statistics

netstat displays active network connections, routing tables, and network interface statistics. Although it has been deprecated in favor of ss, it is still widely used on many systems.

Basic Syntax:

 
netstat [options]

Usage Examples:

  • To display active TCP connections:
     
    netstat -t

  • To display listening ports:
     
    netstat -l

7. ss – The New and Improved Netstat

ss (socket statistics) is a more efficient and faster replacement for netstat. It’s part of the iproute2 package, providing detailed information on network connections, sockets, and more.

Basic Syntax:

 
ss [options]

Usage Examples:

  • To display all active connections:
     
    ss -tuln

  • To filter for specific protocols (e.g., TCP):
     
    ss -t

8. route – Display or Modify the IP Routing Table

The route command shows or modifies the IP routing table. While ip route has largely replaced it, some distributions still support route for backward compatibility.

Basic Syntax:

 
route [options]

Usage Examples:

  • To display the routing table:
     
    route -n

  • To add a new route:
     
    sudo route add default gw 192.168.1.1 eth0

9. dig and nslookup – DNS Lookup

Both dig and nslookup are DNS lookup tools used to troubleshoot domain name resolution issues. dig is often preferred for its flexibility and detailed output.

Usage Example with dig:

 
dig example.com

Usage Example with nslookup:

 
nslookup example.com


Wrapping Up

Learning these commands will give you a powerful toolkit to diagnose, configure, and troubleshoot network issues in Linux. While ifconfig and route are still present on some systems, switching to the ip and ss commands will ensure you’re using the latest, most robust tools available for network management on Linux.

How to find my IP address on Ubuntu Linux (F.A.Q)

What is the Linux equivalent of ipconfig?

The Linux equivalent of ipconfig is the ifconfig command, but it’s now mostly replaced by ip, which provides more functionality. Use ip addr show to display IP addresses and network interfaces.

How do I check my IP address in Linux?

You can use either ifconfig or ip addr show. For example, run ip addr show eth0 to see the IP address assigned to the eth0 interface.

How can I test network connectivity from my Linux terminal?

To test connectivity, use the ping command followed by a website or IP address, like ping google.com. This checks if the device can reach the specified host.

 

What is the difference between netstat and ss?

netstat displays active network connections and routing tables but is being replaced by ss, which provides similar information more efficiently and is part of the modern iproute2 suite. Use ss -tuln to view listening ports and connections.