[Networking] Static IP vs Dynamic IP
Detailed explanations on IPv4 address with the tools and things you need to know; with relatable real life examples
IP Address
The Internet Protocol Address (IP) is a logical address used for host to host communication across the Internet. Every host(s) that wants to communicate with other nodes needs to have at least ONE IP address. There are two versions of IP address; namely the IPv4 and the IPv6 address. An typical IPv4 address looks like this:
192.168.1.1/24IPv4 address is 32-bits long. It contains 4 octets.
Each octet is 8 bits in size.
So, IPv4 address size is: 4 octet x 8 bits = 32 bits
For example, 192.168.1.1.1 is not a valid IPv4 address because it has 5 octets instead of 4 octetsThe valid values for each octet is from 0 to 255.
For example, 192.168.1.256 is not a valid IP because 256 exceeded the range. The /24 here indicates the subnet mask for this address. Subnet mask is used to determine the network boundaries. /24 also means this is a Class C address in classful addressing.
Static IP vs Dynamic IP
Well, how do you get an IPv4 address? There are two ways: (a) static IP or (b) dynamic IP. Static IP is an IP address that is manually configured into the network setting on any host. Meanwhile, Dynamic IP is a random IP assigned by a DHCP server to any hosts (DCHP client) connected to a network.
You should choose a side depending on your use case. Static IP is almost never used in a home network unless there are certain special requirements; you don’t want to go to network setting to configure IP address everytime a new device connects to your Wi-Fi, or you are connecting to other networks. In a home network, the router (given by your ISP) is normally the DHCP server that provides dynamic IP addresses to any connected devices. That explains why your PC gets directly connected to a network (or Internet) once you plug in the LAN cable (RJ45 Ethernet); or when you connect your iPhone to McDonald’s Wifi. In enterprises networks, dynamic IP is normally used to provide IP addresses to workstations due to the large number of devices that are connecting to the networks. In fact, in dynamic IP settings, the very first thing a device would do when trying to connect to a network is ‘to ask for an IP address’ from the DHCP server using the DORA messages.
Then, why do people still uses static IP? In some special use cases, the machine need to be identified by a fixed IP address. For example, if a rogue host sent some malicious packets on the network; this host can be quickly tracked down by checking the source IP of these bad packets. If dynamic IP is used, the network admin would need to check the IP-MAC address binding on the DHCP server to find this rogue host which is more difficult (more on this later). Even in a home network, when there are certain nodes or resources that are shared, like a network printer or a NAS storage; then it is a good idea to assign static IP to them so that they can be ‘reached’. If dynamic IP is used; then discovery protocols like LLDP/SSDP are needed for users to find out what is the IP of these devices.
Also, static IP is almost always used in a data centre (which is a facility that houses the physical servers). Why? The simple intuition is that server is the service provider that constantly talks to a client in a client-server architecture. For example, the Facebook app on our iPhone sends HTTP packets to the Facebook server (somewhere on the Internet) when we browse our news feed. This means that the client (iPhone) needs to know about the Facebook’s server IP so that it knows where to send the packet to (called destination IP). Thus, server IP should be static so that the client are sending packets to the right destination. If servers get their IP from a DHCP server, their IP address are always changing; this means the client devices would need to know the NEW server IP when the DHCP server renews or assigns some new IP to the servers.
Here’s a technical comparison between static IP and dynamic IP:
How to configure static or dynamic IP on end devices
You are probably reading this on your phone or your pc; so it is safe to say that you are currently connected to a network (anyone read from Smart TV?). The point is we have so many different types of devices running on different OS these days; and since the way to configure networks settings on different devices are unique; there is no one-guide-fits-all videos on IP setting. Here are a collection of few videos to set/change IP settings in some popular devices. Also, please remember your default network settings before changing any of the settings just in case you lose your Internet after applying the changes.
How to check my IP settings?
One of the most asked questions to tech support is ‘Why can’t I connect to the Internet’? This is a double-edged sword question; it is easily understood; but somehow it is also difficult to solve. You see, the challenge here is that there are too many factors that contributes to the ‘No Internet’ situation, and to solve this we need to systematically identify and troubleshoot all components along the communication pipeline. For example, you get a website not found error when browsing Amazon.com. Normally, our first instinct would be server is down; but think again, what are the odds of Amazon (a multi-billion dollar company with sophisticated AWS infastructure) of failure compared to our home network using some cheapo router. The point is: from the machine you are browsing on, to your router/modem, the cables (or WiFi channel), the ISP routers and network could be the culprit. So, where do we start the troubleshooting? You start from what you can control of course, which is the end devices and network devices in your home network.
The first step is to make sure our end devices has a valid IP address. The easiest (and nerdy) way to do so is to use the ‘ipconfig’ network command. Note that these network commands are platform dependent, meaning that the tool you use are different, and the commands you typed are also syntactically different. On Windows, open a command prompt window and type ‘ipconfig’ to show the current network settings. To see more information, we type ‘ipconfig /all’. On a MAC or Linux distro, type ‘ifconfig’.
On Windows (use command prompt)
===============================
ipconfig
ipconfig /allOn MAC/Linux (use terminal)
===============================
ifconfig
Here’s the video explaining how to use ipconfig command on the CMD.
You should see some basic network information being displayed and several ‘networks’ are listed. First, you see a few networks like ‘Ethernet’, ‘Wireless LAN adapter Wi-Fi’, Wireless LAN adapter Local Area Connection* 1', ‘Wireless LAN….* 3’ and so on. So what are these? This indicates that on this host, there are several network adapters being installed and used. Each network adapter (called a Network Interface Card, NIC) will have one entry in network information. For example, if your laptop can connect to the Internet using either WiFi connection and Ethernet connection; this means your laptop has 2 NICs. Here, we can guess that this PC have 5 NICs (or sometimes called interfaces). One interesting fact is that not all ‘networks’ you see here is an actual network, some of them can be virtual networks. When virtual adapters are installed (for virtualisation) then more adapters will be displayed in the network information. This means your laptop, having only 2 real interfaces (2 NICs, 1 LAN port and 1 Wi-Fi card) can shows more than 2 networks when you type ‘ipconfig’ in the command prompt.
Second, we need to identify the right interfaces to analyze on. For example, if we want to find out what is my current IPv4 address, you should be looking at the ‘Ethernet adapter vEthernet’ instead of the others. If you are connected to Wi-Fi and LAN at the same time, you will have 2 unique IP address on two different networks. Notice that there are few entries here: the ‘link-local IPv6 address’ indicates the IPv6 address of your PC. This is an automatically generated address by EUI-64. The ‘IPv4 Address’ line shows the current IPv4 assigned to this host, which is 10.0.0.2. This means that anytime this hosts talk to someone, it will use 10.0.0.2 as its source IP address. The ‘subnet mask’ here is 255.255.255.0; which means this is a /24 address. We will cover subnet mask on another story. The ‘default gateway’ is the IP address of the router of the network this PC is currently connected to. Here we can guess that the router is using the 10.0.0.1. Why do you need a router? Simply put, router is needed in every network so that you can talk to other devices on other remote networks on the Internet. This means that if the PC want to talk to any one outside his own network, he need the help of this router to forward the packets to the destination.
Third, if you typed ‘ipconfig /all’ then you will see a whole lots more of network information like this. Here you’ll find more information about the DHCP and DNS servers. Few important lines to highlight here. Notice in the ‘IPv4 Address’ line; there is a ‘preferred’ option added to the address. This indicates that this IPv4 address is assigned by a DHCP server to this host, and the DHCP server remembers this mapping. Think of it as your typical ‘remember me’ in your Facebook or IG. For DHCP, it means that whenever this same PC (refers to the MAC address) leave the network; the DHCP server will reserve this address. When the host re-connects to this network; DHCP will reassign the same IP (192.168.1.142) back to this host. There are few lines of ‘lease’ information; which is showing how long the assigned IP can be used by the host before it is expired. When an IPv4 expired, the host need to renew the lease (sending DORA again) to the DHCP server.
Fourth, check out the line ‘DHCP server’. Notice it is showing the same IP address of the router; which is both 192.168.1.1. This means that the router is also the DHCP server in this network. Intuitively, when you add a new host to the network, this particular host will send a DORA, and the router will reply to this host with an IPv4 address. Then check out the line ‘DNS servers’. DNS server, which stands for domain name resolution; is used to translate web URLs to IP address. DNS server IP is always provided together by DHCP server to the host. When a user browse www.google.com; the HTTP request is sent to the DNS server. Then, DNS server will do a lookup to find the real IP address of the server hosting www.google.com; for example, 100.100.100.100 and return its IP to the host. In this way, the host will know the that to browse google.com; it needs to send the packets to Google’s server with the destination IP address 100.100.100.100. Without the DNS server, a host having a valid IP can connects to the Internet but cannot browse any websites (unless you key in the server IP manually after nslookup). Here we can imply that this PC is using 3 DNS servers; 24.200.243.189, 24.200.210.241, 24.200.228.113. It is normal to have multiple DNS servers, so that one would act as the main DNS, and the rest as secondary DNS.
Advance ipconfig options
TBA
How to know if I’m connected to the Internet
Is there anything more frustrating that not able to connect to the Internet? Turned out that; it is actually more frustrating if you are CONNECTED to the network but there is NO INTERNET.
In some cases, we’ve checked that our PC is connected to the network, the IP address is valid, but when we browse google.com it shows that ‘you are not connected to the Internet’. Why does this happened? You see, there is actually two different parts of connection; the first one is between your device to the router (private network); and the second one is between your router to the Internet (public network). When you are connected to your own LAN, this means that your device can communicate to anyone within the same LAN; even if you are not subscribed to any ISP. However, for your device to talk to other devices outside your LAN, the traffic need to go to your router, and to other routers in the public network before finally reaching the destination. So there are a few possibilities to this:
- You did not pay the Internet bills; and the ISP has blocked your Internet account. A problem that money can solve is not really a problem.
- You paid your bills, but there is something wrong with the ISP settings on user accounts and Identity management. You need to call up your ISP customer support.
- There are some technical issues on the ISP sides; perhaps they misconfigured some of the network devices, routing is messed up, or some infastructure are broken and need repairs. You need to call up the ISP tech support.
- It could be the server or websites that you are trying to reach is temporarily not available, due to server overload or maintanence. Time will fix this, try again later.
- The DNS server is not resolving the URLs properly. Perhaps the site you are browsing is blocked at the DNS level. Alternatively, set your DNS server to Google’s DNS at 8.8.8.8
- There are some misconfigurations in the network, especially if you are using static IP. Check if the assigned IP is within the usable range, if the gateway IP is set to router’s IP, and the DNS server IP is assigned correctly. Also check if there is any proxy settings that is preventing you to go online.
- Sometimes, it could just be that the connection is slow. Perhaps you are connected but web pages take ages to load so you think you are not. If you are on Wi-Fi, try to tweak the Wireless AP settings like boosting signal strength or changing the channels.
- Or perhaps, you had enough Internet for today. In this case, restarting the router and reset network setting on the devices would work wonder.