Networking Basics Part 2
Let's see some linux commands related to Network

Let’s use ping command to initiate communication with another devioce in the local network.
labex:~/ $ ip route show
default via 172.16.50.253 dev eth0 proto dhcp src 172.16.50.154 metric 100
100.100.2.136 via 172.16.50.253 dev eth0 proto dhcp src 172.16.50.154 metric 100
##From the example output above, the gateway's IP address is 172.16.50.253.
##Now, use this IP address to send a few ping packets.
##The -c 4 option tells ping to send exactly 4 packets and then stop.
labex:~/ $ ping -c 4 172.16.50.253
PING 172.16.50.253 (172.16.50.253) 56(84) bytes of data.
64 bytes from 172.16.50.253: icmp_seq=1 ttl=64 time=0.060 ms
64 bytes from 172.16.50.253: icmp_seq=2 ttl=64 time=0.042 ms
64 bytes from 172.16.50.253: icmp_seq=3 ttl=64 time=0.091 ms
64 bytes from 172.16.50.253: icmp_seq=4 ttl=64 time=0.066 ms
--- 172.16.50.253 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3063ms
rtt min/avg/max/mdev = 0.042/0.064/0.091/0.017 ms
Configuring secondary Static IP address
Let’s assign a secondary IP address to the network interface. A static IP address is quite useful for the server that need to be consistently reachable at the same address.
labex:~/ $ sudo ip addr add 192.168.1.10/24 dev eth0
labex:~/ $ ip a show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:16:3e:0c:78:e6 brd ff:ff:ff:ff:ff:ff
altname enp0s5
altname ens5
inet 172.16.50.173/24 metric 100 brd 172.16.50.255 scope global dynamic eth0
valid_lft 1892159518sec preferred_lft 1892159518sec
inet 192.168.1.10/24 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::216:3eff:fe0c:78e6/64 scope link
valid_lft forever preferred_lft forever
Listing all active listening socket
labex:~/ $ netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3002 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3001 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN
tcp 0 0 localhost:domain 0.0.0.0:* LISTEN
tcp 0 0 localhost:42521 0.0.0.0:* LISTEN
tcp 0 0 iZrj9iw67vkstklwa:38632 100.100.166.166:https TIME_WAIT
tcp 0 0 iZrj9iw67vkstklwa:58270 100.100.100.200:http TIME_WAIT
tcp 0 0 iZrj9iw67vkstklwa:59108 100.100.88.88:http TIME_WAIT
.
.
.
Subnet
A subnet is a group of IP addresses that are similar in a certain way. The devices are usually in a proximate location from each other and you can easily send to and from hosts on the same subnet. It’s like delivering something to your nebougherhood with ease.
For example, all hosts with an IP address that starts with 123.45.67 would be on the same subnet. 1st host has an IP of 123.45.67.8, and 2nd has an IP of 123.45.67.9. The common numbers are 1st network prefix, and the 8 and 9 are the hosts; therefore, 1st network is the same as 2nd. A subnet is divided into a network prefix, such as 123.45.67.0, and a subnet mask.
IPv4: An IPv4 address is a 32 bit number typically represented in a human readable format: Ex - 204.23.124.23 This contains 2 distinct parts.
The network portion which identifies the specific network the device is on.
The host portion which identifies the specific device on that network.
Subnet Mask: It determines what part of your IP address in the network portion and what part is host portion. Typical subnet mask can look something like this: 255.255.255.0
Subnetting is used to segment the networks and control the flow of traffic within that network. So a host on a subnet can’t interact with another host on a different subnet.
To connect subnets, you just need to find the hosts that are connected to more than one subnet. For example, if my host at 192.168.1.129 is connected to a local network of 192.168.1.129/24, it can reach any hosts on that network. To reach hosts on the rest of the Internet, it needs to communicate through the router. Traditionally, on most networks with a subnet mask of 255.255.255.0, the router is usually at address 1 of the subnet, so 192.168.1.1. Now that router will have a port that connects it to another subnet.
Router
A router enables machines on a network to communicate with each other as well as with other networks.
On a typical router, you will have LAN ports that allow your machines to connect to the same local area network, and you will also have an internet uplink port that connects you to the internet. Sometimes you'll see this port labeled as WAN because it is essentially connecting you to a wider network.
When we do any sort of networking activity, it has to go through the router. The router decides where our network packets go and which ones come in. It routes our packets between multiple networks to get from their source host to their destination host.
DNS - Domain Name System
DNS allows us humans to keep track of websites and hosts by name instead of an IP address.
Imagine if every time you wanted to do a search on Google you had to type in http://192.78.12.4 instead of www.google.com.
It's like a contact list for the Internet. If you know someone's name but don’t know their phone number, you can simply look it up in your contacts list.
DNS is fundamentally a distributed database of hostnames to IP addresses.



