# Lab 5. Subnetting and Linux Networking ## *Kseniya Evdokimova* --- ## **Questions to answer:** ### I. You have a range 172.16.200.0/22 **Identify subnet range:** with the mask /22 we can have subnet range from 172.16.200.0 to 172.16.203.255, where 172.16.200.0 is a subnetwork address and the last one (172.16.203.255) is a broadcast address, *with all the ones in between are host addresses.* We reach that answer by overlaying mask in the binary form (where first 22 digits are 1s and the rest are zeroes) over the 172.16.200.0 in the binary form (10101100.00010000.11001000.00000000). All digits that were overlaped by 0s we will turn consistently into 0s (that way we will reach the first border - 172.16.200.0) and then into 1s (that way we will reach the first border - 172.16.203.255); all digits that were overlaped by 1s will stay the same. **How many usable IP addresses?** We can calculate the number of usable IP addresses in the subnetwork with the formula `2^32 - 2^22 - 2`, which is equal to 1022. **Identify starting IP and ending IP** As was mentioned in the first answer, 172.16.200.1 is the starting host IP and 172.16.203.254 is the ending IP, since 172.16.200.0 is reserved for the subnetwork address and 172.16.203.255 is reserved for the broadcast address. ### II. You have a range 10.16.200.12/17 **Identify subnet range:** with the mask 17 we can have subnet range from 10.16.128.0 to 10.16.255.255, where 10.16.128.0 is a subnetwork address and the last one (10.16.255.255) is a broadcast address, *with all the ones in between are host addresses*. We reach that answer by overlaying mask in the binary form (where first 17 digits are 1s and the rest are zeroes) over the 10.16.200.12 in the binary form (00001010.00010000.11001000.00001100). All digits that were overlaped by 0s we will turn consistently into 0s (that way we will reach the first border - 172.16.200.0) and then into 1s (that way we will reach the first border - 172.16.203.255); all digits that were overlaped by 1s will stay the same. **How many usable IP addresses?** We can calculate the number of usable IP addresses in the subnetwork with the formula `2^32 - 2^17 - 2`, which is 32766. **Identify starting IP and ending IP** As was mentioned in the first answer, 10.16.128.1 is the starting host IP and 10.16.255.254 is the ending IP, since 10.16.128.0 is reserved for the subnetwork address and 10.16.255.255 is reserved for the broadcast address. ### III. You have a range 192.168.0.0/24 and devide into small subnets *Subnet with 29 hosts Subnet with 120 hosts Subnet with 60 hosts* To solve this problem, we will start with the biggest block (120) and keep going down. So, we need a minimum subnet of /25 to accommodate 120 hosts. Therefore, we can split the 192.168.0.0/25 block into two subnets: 192.168.0.0/25 192.168.0.128/25 We can use the first subnet 192.168.0.0/25 for the 120 hosts leaving us with the other subnet, 192.168.0.128/25. The next largest subnet needs 60 hosts which can be accommodated with a /26 subnet. This means we can split the 192.168.0.128/25 subnet into two smaller subnets: 192.168.0.128/26 192.168.0.192/26 We can use the 192.168.0.128/26 subnet for the network requiring 60 hosts leaving us with the 192.168.0.192/26 subnet to further break down. The last subnet require 29 hosts meaning we need a minimum of /27 subnets. Therefore, we can split the 192.168.0.192/26 subnet into 2 smaller subnets: 192.168.0.192/27 192.168.0.224/27 Therefore, our subnets are: **192.168.0.0/25 for the network with 120 hosts 192.168.0.128/26 for the network with 60 hosts 192.168.0.192/27 for the network with 29 hosts** This means we still have the subnet (192.168.0.224/27) to use in the future. ## **Questions to answer:** ### 1. Add several IP adresses to interface using by netplan and ping them. - The first step toward setting up a static IP address is identifying the name of the ethernet interface you want to configure. To do so, use the ip link command, as shown below: `$ip link` - The command prints a list of all the available network interfaces. In this example, the name of the interface is eth0: ![](https://i.imgur.com/o5Xd3ye.png) - If your Ubuntu cloud instance is provisioned with cloud-init, you’ll need to disable it. To do so create the following file: `$vim /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg` And into this document we will put: ![](https://i.imgur.com/kprwjyP.png) It is successfully saved: ![](https://i.imgur.com/QiYSSrY.png) - We can also check what is in the /etc/netplan directory: ![](https://i.imgur.com/B5AS8Ll.png) - We need to add `/etc/netplan/01-netcfg.yaml` by running: `vim /etc/netplan/01-netcfg.yaml` And writing into it: ![](https://i.imgur.com/AWQfAIZ.png) It is successfully saved: ![](https://i.imgur.com/0pMRU9Q.png) - When editing Yaml files, make sure you follow the YAML code indent standards. If the syntax is not correct, the changes will not be applied. Once done, save the file, test for syntaxes and then apply the changes by running the following commands: `$netplan try` `$netplan apply` Nevertheless, as was mentioned in the Netplan configuration examples (the link https://netplan.io/examples/ was provided in the lab), Interface aliases (e.g. eth0:0) are not supported, but it is the only one I have received with the `ip link` command. - The other method to solve this is running `sudo ip addr add 192.168.56.203/24 dev eth0 label eth0:0` command And then we will check it by `ip addr` ![](https://i.imgur.com/kbjAtiS.png) We see the provided changes in the picture above - The same way we can add as many IP addresses as we want ![](https://i.imgur.com/bd5BtIW.png)