Static IP configuration - Windows, Linux, Mac os
Welcome to my blog, on this one, we are going to analyze the different options we have to assign a static IP to our computer/server. In this case, the post is going to be divided in 2 parts, one for each method, both are explained for Windows, Linux and macOS. This tutorial will be part from a series of projects, on which ones, the installation and configuration of Raspbian and the static IP assignation are going to be basic steps to be done, and will appear on the header of each project that requires those steps.
What means to assign a static IP to your computer?
Before starting, I would like to explain which is the objective of assigning a static IP. OK, all the devices we connected to internet, have 2 IPs, one public and one private. The private, is the one that represents our device inside our home/work network, usually follows this structure; 192.168.1.xxx or 192.168.0.xxx. The public one, represents externally our home/work network. Inside the private network we can have as many IPS as our "as we want", but when we go outside, to internet, all the devices we have on our network **will have the same public IP, **this one can and usually does change with time.
Which is the reason to have 2 IPs? With the current protocol of IP distribution (IPV4) exist a maximum number of IPs that can be distributed. IPV4 uses 32 bits addresses, limiting it to 2^32 = 4,294,967,296 unique IPs. That means that are not enough IP for all. That's why there is only 1 IP per network. This address is assigned by our ISP or internet provider and, excluding some cases, we can't choose it. But we can modify our private one, following the structure of 192.168.1/0.xxx
Your router is the manager of all this. For each device/computer we connect to the router, this will assign a private IP by DHCP. Usually this IP is reserved to the device for a time, once the time finishes the router will assign another IP. Router itself decides what IP.
The problem is when we want to connect remotely using SSH and the device's IP. IF this IP changes, we have to look for the new IP and connect to it using the new one. Another problem is when we open ports on our router for a specific device/IP. And again, if the IP changes the port remains open but not for our device that has a new IP. To avoid this problem, we assign a static IP, so we know that the device will always have the same IP.
For assigning a static IP, we have two methods, the first one is to configure the router to assign always the same IP or configuring the computer to ask always for the same IP.
I recommend doing the first one, as it is easier to administrate.
Option 1: Configuring the router
This step depends on each router module. On this tutorial I'm going to saw the general steps for configuring a static IP over the router, may your router have a different procedure to do, but as I can't explain all the routers of the world, will explain only the general steps.
The first step is to connect to the router, we can do that by opening the browser and writing:
Once we are, we will ask for user and password: unless the pass is printed on the router, the user/password usually are:
1234/1234, 1234/admin, admin/admin,...
You can also ask your ISP or provider, or knowing the brand of your router you can check it on this page: http://www.routerpasswords.com/
After inserting the user and password, we will have to look for static IP or static DHCP. Normally this option is on Advanced Options or something similar.
In my case: Advanced Options > Network Settings > LAN > Static DHCP. Each router has a different structure and menu, but is going to be something similar to mine.
Now you have found that option, we are going to add a new rule or address. At this point, you will have to insert MAC address and the IP you wanted to be as static IP. The MAC is going to tell the router which device is going to have that address statically. As always, the IP must follow this structure 192.168.1.xxx or 192.168.0.xxx and must be inside routers range of IPs. Here is how you can find the MAC or physical address of your computer.
Open CMD or PowerShell, and type:
Search: Physical Address and copy that. Will have the following format: XX-XX-XX-XX-XX-XX, being X letters and numbers.
Search for: HWaddr and copy address. Will have the following format: XX:XX:XX:XX:XX:XX, being X letters and numbers.
Depending on if we are using Wi-Fi or Ethernet, search: Ethernet Address and copy address. Will have the following format: XX:XX:XX:XX:XX:XX, being X letters and numbers.
Insert both addresses: MAC and the IP we want to have or computer/device.
Option 2: Configuring the computer
Go to Control Panel > Network and Internet > Network and sharing center. On the right sidebar, click on: Change adapter settings. Depending if you are on Wi-Fi or Ethernet cable, select the right adapter and right click > Properties.
On the new windows, insert those addresses and your IP.
You will see the Ethernet interfaces starting with eth abbreviation, Wireless interfaces WLAN begin with the abbreviation wan and also have a network interface called: loopback with the abbreviation lo, which serves for checking connectivity to your own machine at 127.0.0.1 IP address. In my case I have only one interface called eth0 (Ethernet) and loopback as you can see in the picture below :
Edit the following file if network interfaces, you can do so by:
sudo nano /etc/network/interfaces
On this file, you will have to assign a static IP for each interface you want. We are going to do only eth0:
iface eth0 inet static address 192.168.1.50 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1
See that we did the example for a Network as follows: 192.168.1.0\24, yours can be 192.168.0.0\24 or even different.
Restart the network interfaces for applying the changes:
sudo /etc/init.d/networking restart
Or, will also work:
sudo ifconfig eth0 down sudo ifconfig eth0 up
For Raspberry Pi, this is the step you will have to do, or the option 1.
Mac OS X
Go to Apples Icon > System Preferences > Network. Click on Advanced button. And to TCP/IP tab. Open IPv4 Configuration and select Manually.
The IP, choose the one you want. 192.168.1.XXX, remember that must be inside router's range.
Gateway must be your router's entry address, normally: 192.168.1.1.
As DNS servers, you can add the ones you want. Or for example Google's ones: 22.214.171.124/126.96.36.199
Congratulations, you have assigned a Static IP to your computer successfully.
See you on the next!