BLOGS

IP Address

Published Mar 30, 2020 - Author: zgxsin

Share

What is IP Address

Please check this video to get an intuitive understanding of IP address if you have no idea of it.

https://www.youtube.com/watch?v=8zEVA-Bxs-0

Public IP Address

A public IP address is an IP address that your home or business router receives from your ISP. Public IP addresses are required for any publicly accessible network hardware such as a home router and the servers that host websites ((https://www.lifewire.com/what-is-a-public-ip-address-2625974)). To get your public IP address, you can simply type

curl ifconfig.me

in your terminal and then you will see you public IP address.

Dynamic IP Address

Every time your device is connected to the internet, the internet service provider (ISP) will allocate an IP address for your device from their available IP addresses. Since this IP address is changing every time, it is called dynamic IP address.

Static IP Address

Static IP address is the permanent internet address and never changes. It is an IP address that was manually configured for a device, versus one that was assigned by a DHCP server. It's called static because it doesn't change.

A static IP address is useful when you host a website of your own. Because this address won't change, so other people will always know how to connect to it once they know your static IP address.

Private IP Address

A private IP address is an unique identifier for all the devices behind a router or other device that serves IP addresses. The static IP address in most ways works the same as public IP address.

With private IP addresses, the devices in your home can have the same private IP addresses as your neighbor's devices, or anyone else's all around the world.

When you open a website from your laptop, the request is sent from the laptop to the router as a private IP address, after which the router requests the website from your ISP using the public IP address assigned to your network. Once the request has been made, the operations are reversed — the ISP sends the address of the website to your router, which forwards the address to the laptop that asked for it.

Understanding ip addr show

In Linux system, we use

ip addr show 

to check the private IP address of the device. ifconfig is not recommended ((https://blog.cyphermox.net/2017/05/if-youre-still-using-ifconfig-youre.html)).

The result from this command is a little complex.

Here are the explanations. I briefly list it here and add detailed information.

Each device is given an sequential number as an identifying number. This is merely a convenience, and should not be used to refer to devices. The second field in an entry is the interface name (which usually corresponds to the device name). Next, we see the device flags and maximum transmission unit size. The final fields in the first line of output for each device entry refer to the traffic control queuing discipline (qdisc) and the Ethernet buffer transmit queue length (qlen). For more on understanding and using traffic control under linux, see the LARTC documentation.

The second line of output describes the link layer characteristics of the device. For Ethernet devices, this will always say "link/ether" followed by the hardware address of the device and the media broadcast address. For more detail on the link layer characteristics of a device see here.

Subsequent lines of output describe the IP addresses available on each interface. In a typical installation only one address is used on each interface, although an arbitrary number of addresses can also be used on each interface. Each line contains the IP address and netmask in CIDR notation, an optional broadcast address, scope information and a label. Let's examine the scope and label first and then discuss IP addressing and broadcast calculation. The possible values for scope are outlined in the following table.

ScopeDescription
globalvalid everywhere
sitevalid only within this site (IPv6)
linkvalid only on this device
hostvalid only inside this host (machine)

Scope is normally determined by the ip utility without explicit use on the command line. For example, an IP address in the 127.0.0.0/8 range falls in the range of localhost IPs, so should not be routed out any device. This explains the presence of the host scope for addresses bound to interface lo. Usually, addresses on other interfaces are public interfaces, which means that their scope will be global. 

Detailed Explanation

Interface flags are listed in the angle brackets. Check the flags here and here.

  • UP

The interface is turned on. It is ready to accept packets for transmission and it may inject into the kernel packets received from other nodes on the network.

  • LOOPBACK

The interface does not communicate with other hosts. All packets sent through it will be returned and nothing but bounced packets can be received.

  • BROADCAST

The interface has the facility to send packets to all hosts sharing the same link. A typical example is an Ethernet link.

  • POINTOPOINT

The link has only two ends with one node attached to each end. All packets sent to this link will reach the peer and all packets received by us came from this single peer. If neither LOOPBACK nor BROADCAST nor POINTOPOINT are set, the interface is assumed to be NMBA (Non-Broadcast Multi-Access). This is the most generic type of device and the most complicated one, because the host attached to a NBMA link has no means to send to anyone without additionally configured information.

  • MULTICAST

It is an advisory flag indicating that the interface is aware of multi- casting i.e. sending packets to some subset of neighboring nodes. Broadcasting is a particular case of multi-casting, where the multicast group consists of all nodes on the link. It is important to emphasize that software must not interpret the absence of this flag as the inability to use multi-casting on this interface. Any POINTOPOINT and BROADCAST link is multi-casting by definition, because we have direct access to all the neighbors and, hence, to any part of them. Certainly, the use of high bandwidth multicast transfers is not recommended on broadcast-only links because of high expense, but it is not strictly prohibited.

  • PROMISC

The interface listens to and feeds to the kernel all traffic on the link even if it is not destined for us, not broadcasted and not destined for a multicast group of which we are member. Usually this mode exists only on broadcast links and is used by bridges and for network monitoring.

  • ALLMULTI

The interface receives all multicast packets wandering on the link. This mode is used by multicast routers.

  • NOARP

This flag is different from the other ones. It has no invariant value and its interpretation depends on the network protocols involved. As a rule, it indicates that the device needs no address resolution and that the software or hardware knows how to deliver packets without any help from the protocol stacks.

  • DYNAMIC

It is an advisory flag indicating that the interface is dynamically created and destroyed.

  • SLAVE

This interface is bonded to some other interfaces to share link capacities.

  • LOWER_UP

Driver signals L1 up (since Linux 2.6.17) . LOWER_UP is a physical layer link flag (the layer below the network layer, where IP is generally located). LOWER_UP indicates that an Ethernet cable was plugged in and that the device is connected to the network. LOWER_UP differs from UP, which additionally requires the network interface to be enabled.

NB. There are other flags but they are either obsolete (NOTRAILERS) or not implemented (DEBUG) or specific to some devices (MASTER, AUTOMEDIA and PORTSEL). We do not discuss them here.

Here we take the interface 2 in our example for clarification.

  • enp6s0f1 

It is the interface name. It can be any string.

  • mtu 1500 

it sets maximum transmission unit = 1500 bytes, this is the largest size that a frame sent over this interface can be. This number is usually limited by the Ethernet protocol's cap of 1500. If you send a larger packet and it arrives at an Ethernet interface, then the frame will get fragmented and its payload transmitted in 2 or more packets. Not really any benefit to that, so it's best to follow standards.

It sets queuing discipline = combines Fair Queuing with the CoDel AQM scheme, this determines how an interface chooses which packet to transmit next, when it's being overloaded. Particularly, noqueue means that this interface does not queue anything and loop means that the interface s in the black-hole mode, i.e. all packets sent to it are immediately discarded.

  • group default 

Interface groups give a single interface to clients by combining the capabilities of the aggregated interfaces on them.

  • qlen 1000 

It sets transmission queue length = 1000 packets. The 1000th packet will be queued, the 1001st will be dropped.

  • link/ether 

It means the link layer protocol is Ethernet, the content afterwards is MAC address. The laptop doesn't have a MAC address. The network card has a MAC address. So if you have a wireless card and an Ethernet card, you'll have two MAC addresses.

  • brd 

It means broadcast. This is the address that the device will set as destination when it sends a broadcast. An interface sees all traffic on the wire it's sitting on, but is polite enough to only read data addressed to it. The way you address an interface is by using it's specific address, or the broadcast address.

  • inet 

It means the network layer protocol is internet (ipv4). inet6 meas network layer protocol is internet (ipv6). The number directly after the inet address is the number of 1s in its subnet mask.

  • valid_lft/preferred_lft 

It stands for lifetime. If you get this address through DHCP, then you'll have a valid lifetime for your lease on the IP address. And just to make hand-offs a little bit easier, a (probably) shorter preferred lifetime is set.

[thumbs-rating-buttons]