IP and Routing in Linux
Tuyen D. Le September 03, 2023 [Server] #ip #routingIP
# Assign static IP for Ubuntu 14, 16
Commonly used IP addresses:
- The last octet of a network address is 0, gateway address is 255
127.0.0.1
loopback0.0.0.0
IP address does not exist
Route trong Linux
- Routing table using Longest Prefix Match. For example
192.168.0.0/16 next-hop 10.0.0.1 IF1
192.168.1.0/24 next-hop 11.0.0.1 IF2
192.168.1.128/25 next-hop 12.0.0.1 IF3
- Thus, when you want to send a message to
192.168.1.129
, you will send it via192.168.1.128/28 IF3
route -n
or ip route show
Flags:
- G: using gateway, the difference between with and without this flag is shown below.
- U: up - active status
route add
Indivisual host Destination | Subnet Destionation |
---|---|
route add -net 205.192.25.0 netmask 255.255.255.0 dev eth3 | route add -net 205.192.25.0/24 gw 203.162.5.1 |
route -n | route -n |
205.192.25.0 0.0.0.0 U eth3 | 205.192.25.0 203.162.5.1 UG eth3 |
When you want to send a package to IP 205.192.25.5 , | |
Des. IP: 205.192.25.5 | Des. IP: 205.192.25.5 |
Des. Mac: ARP who is 205.192.25.5 | Des. Mac: ARP who is 203.162.5.1 |
How is the travel packet in the network?
No. | IP src. | IP des. | MAC src. | MAC des. |
---|---|---|---|---|
1 | 192.168.10.2 | 172.16.0.10 | 0E3 | 401 |
2 | 192.168.10.2 | 172.16.0.10 | 402 | B01 |
3 | 192.168.10.2 | 172.16.0.10 | B02 | 224 |
Conclude
- IP address src. and IP des. unchanged when traversing the network (in the case of no NAT)
- MAC address src. and MAC des. is changed when passing through each Router