Skip to content

KodeCloud Networking

Links: 111 KodeCloud Index



attachments/Pasted image 20220915180827.jpg
- We can connect two computers using a switch - To connect these computers to a switch we need an interface on each host. - This interface can be physical or virtual.

The very first requirement of assigning an IP address to a system is that it must have a physical or virtual interface.
  • To see the interfaces for the host we use the ip link command
  • Assuming switch has an IP address of we assign IP addresses to our interfaces.
  • Once the IP addresses have been assigned the computers can now connect with each other.


  • A router helps connect two networks.
    • attachments/Pasted image 20220915181026.jpg


  • We configure a gateway to let machine B know how to reach machine C.
  • The system's need to know the address of the gateway.
    • This can be done using the route command. This will display kernel's routing table.
  • Adding a gateway
    • attachments/Pasted image 20220915181246.jpg
  • Default gateway entry is used to route to the internet
    • Any request outside of your network goes to the default gateway.
    • Instead of default we can also use
    • attachments/Pasted image 20220915181518.jpg
Suppose if you have 2 different routers then you will need two different entries.

attachments/Pasted image 20220915181701.jpg

Using Linux Host as a router

  • How do we connect A to C
    • attachments/Pasted image 20220915181837.jpg
  • We add a routing table entry to A saying it has to go through B to reach C
    • ip route add via
  • Similarly we also need to let host C know that it can reach A using B.
    • ip route add via
This still won't be enough because by default in linux packets are not forwarded.

This is for security reasons. Suppose your eth0 is connected to internet and your eth1 is connected to your private network. We don't want anyone from the internet to send packets to your private network.

  • Whether a host can forward packets is governed by /proc/sys/net/ipv4/ip_forward
    • By default value in this file is set to 0.
    • Setting this to 1 should enable packet forwarding.
  • Just changing this won't persist the changes on reboot we need to also change /etc/sysctl.conf


We can configure a custom DNS resolver by adding its entry to /etc/resolv.conf

This is particularly useful when you have a lot of machines and you want to reference them using their names and don't want to modify each machine's /etc/hosts file. attachments/Pasted image 20220915193336.jpg

  • By default for DNS resolution the system first looks into the /etc/hosts file and then looks for the DNS resolver.

    • This order can be changed in /etc/nsswitch.conf
      • attachments/Pasted image 20220915192607.jpg
  • We can configure the custom DNS to forward all the requests to the public name servers (like google or Cloudflare) if the entry is not present in our custom DNS.

    • attachments/Pasted image 20220915193041.jpg
DNS troubleshooting tools like dig and nslookup doesn't consider the entries of /etc/hosts file.

Search domain

  • It is the domain name that gets appended.
    • attachments/Pasted image 20220915193624.jpg
  • The host is intelligent enough that if you type then it won't append to it.

Last updated: 2022-09-15