Network Basic
Network Basic
Network Basic
NETWORKING
BASICS
Switching ??
A eth0 eth0 B
192.168.1.0
192.168.1.10 192.168.1.11
ip link ip link
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
fq_codel state UP mode DEFAULT group default qlen 1000 fq_codel state UP mode DEFAULT group default qlen 1000
ip addr add 192.168.1.10/24 dev eth0 ip addr add 192.168.1.11/24 dev eth0
ping 192.168.1.11
Reply from 192.168.1.11: bytes=32 time=4ms TTL=117
Reply from 192.168.1.11: bytes=32 time=4ms TTL=117
Routing ??
192.168.1.1 192.168.2.1
Gateway
192.168.1.1 192.168.2.1
route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.1 192.168.2.1
172.217.194.0
INTERNET
216.134.45.0
INTERNET
16.44.53.0
192.168.1.1 192.168.2.1
ip
iproute
routeadd
add172.217.194.0/24 via 192.168.2.1
default via 192.168.2.1
route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 192.168.2.1 255.255.255.0 UG 0 0 0 eth0
172.217.194.0
0.0.0.0 192.168.2.1
192.168.2.1 255.255.255.0
255.255.255.0 UG
UG 0
0 0
0 0
0 eth0
eth0
default
192.168.2.0 192.168.2.1
0.0.0.0 255.255.255.0
255.255.255.0 UG
UG 0
0 0
0 0
0 eth0
eth0
Default Gateway INTERNET
172.217.194.0
INTERNET
216.134.45.0
INTERNET
16.44.53.0
192.168.2.1
192.168.1.1
192.168.2.2
route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0
default 192.168.2.1 255.255.255.0 UG 0 0 0 eth0
192.168.1.0 192.168.2.2 255.255.255.0 UG 0 0 0 eth0
??
192.168.1.5
192.168.1.6 192.168.2.6 192.168.2.5
ping 192.168.2.5
Connect: Network is unreachable
ip route add 192.168.2.0/24 via 192.168.1.6 ip route add 192.168.1.0/24 via 192.168.2.6
ping 192.168.2.5
A eth0 192.168.1.0 eth0 B eth1
192.168.2.0
eth0
C
192.168.1.5
192.168.1.6 192.168.2.6 192.168.2.5
cat /proc/sys/net/ipv4/ip_forward
0
/etc/sysctl.conf
.6 echo 1 > /proc/sys/net/ipv4/ip_forward …
net.ipv4.ip_forward = 1
1 …
ping 192.168.2.5
Reply from 192.168.2.5: bytes=32 time=4ms TTL=117
Reply from 192.168.2.5: bytes=32 time=4ms TTL=117
Reply from 192.168.2.5: bytes=32 time=4ms TTL=117
Reply from 192.168.2.5: bytes=32 time=4ms TTL=117
Take Aways
ip link
ip addr
ip route route
cat /proc/sys/net/ipv4/ip_forward
1
13
DNS
For the Absolute Beginners
db
A eth0 eth0 B
192.168.1.0
192.168.1.10 192.168.1.11
ping 192.168.1.11
Reply from 192.168.1.11: bytes=32 time=4ms TTL=117
Reply from 192.168.1.11: bytes=32 time=4ms TTL=117
ping db
ping: unknown host db
db
A eth0 eth0 B
192.168.1.0
192.168.1.10 192.168.1.11
ping db hostname
host-2
ping: unknown host db
ping db
PING db (192.168.1.11) 56(84) bytes of data.
64 bytes from db (192.168.1.11): icmp_seq=1 ttl=64 time=0.052 ms
64 bytes from db (192.168.1.11): icmp_seq=2 ttl=64 time=0.079 ms
db
A eth0 eth0 B
192.168.1.0
192.168.1.10 192.168.1.11
ping db
PING db (192.168.1.11) 56(84) bytes of data.
64 bytes from db (192.168.1.11): icmp_seq=1 ttl=64 time=0.052 ms
64 bytes from db (192.168.1.11): icmp_seq=2 ttl=64 time=0.079 ms
ping www.google.com
PING www.google.com (192.168.1.11) 56(84) bytes of data.
64 bytes from www.google.com (192.168.1.11): icmp_seq=1 ttl=64 time=0.052 ms
64 bytes from www.google.com (192.168.1.11): icmp_seq=2 ttl=64 time=0.079 ms
Name Resolution
db
A eth0 eth0 B
192.168.1.0
192.168.1.10 192.168.1.11
ping db
ssh db
curl http://www.google.com
Name Resolution web db
A eth0 eth0 B
192.168.1.0
192.168.1.10 192.168.1.11
C
cat >> /etc/hosts nfs
192.168.1.10 web
192.168.1.11 db
192.168.1.12 nfs 192.168.1.12
Name Resolution
A eth0
eth0 B
192.168.1.0
cat >> /etc/hosts
192.168.1.10 web
192.168.1.11 db
192.168.1.12 nfs
192.168.1.20 web
192.168.1.21 db-1
192.168.1.22 nfs-1
192.168.1.30 web-1
192.168.1.31 db-2
192.168.1.32 nfs-2
192.168.1.40 web-2
192.168.1.41 sql
192.168.1.42 web-5
192.168.1.50 web-test
192.168.1.61 db-prod
192.168.1.52 nfs-4 eth0 eth0 eth0
192.168.1.60 eth0
web-3 eth0 eth0 eth0 eth0
192.168.1.61 db-test
192.168.1.62 nfs-prod
Z D S W C P L K
192.168.1.10 web
192.168.1.11 db
DNS
192.168.1.12 nfs
192.168.1.20 web
192.168.1.21 db-1
192.168.1.22
192.168.1.30
192.168.1.31
nfs-1
web-1
db-2
eth0 DNS
192.168.1.32 nfs-2
192.168.1.40 web-2
192.168.1.41 sql
192.168.1.42 web-5
192.168.1.50 web-test
192.168.1.61 db-prod
192.168.1.52 nfs-4
192.168.1.60 web-3
192.168.1.61 db-test
192.168.1.62 nfs-prod
A eth0
192.168.1.0
cat >> /etc/hosts
eth0 B
C C C C C C C C
DNS
192.168.1.10 web
192.168.1.11 db
192.168.1.12 nfs
A eth0 192.168.1.20
192.168.1.21
web
db-1
192.168.1.22 nfs-1
192.168.1.30 web-1
192.168.1.31 db-2
192.168.1.32
192.168.1.40
nfs-2
web-2 eth0 DNS
192.168.1.41 sql
192.168.1.42 web-5
192.168.1.10 192.168.1.0 192.168.1.50
192.168.1.61
web-test
db-prod
192.168.1.52 nfs-4
192.168.1.60 web-3
192.168.1.61 db-test
192.168.1.62 nfs-prod
192.168.1.100
cat /etc/resolv.conf
nameserver 192.168.1.100
ping db
PING db (192.168.1.11) 56(84) bytes of data.
64 bytes from db (192.168.1.11): icmp_seq=1 ttl=64 time=0.052 ms
64 bytes from db (192.168.1.11): icmp_seq=2 ttl=64 time=0.079 ms
DNS
192.168.1.10 web
192.168.1.11 db
192.168.1.12 nfs
A eth0 192.168.1.20
192.168.1.21
web
db-1
192.168.1.22 nfs-1
192.168.1.30 web-1
192.168.1.31 db-2
192.168.1.32
192.168.1.40
nfs-2
web-2 eth0 DNS
192.168.1.41 sql
192.168.1.42 web-5
192.168.1.10 192.168.1.0 192.168.1.50
192.168.1.61
web-test
db-prod
192.168.1.52 nfs-4
192.168.1.60 web-3
192.168.1.61
192.168.1.116 db-test
test
192.168.1.62 nfs-prod
192.168.1.100
cat /etc/resolv.conf
nameserver 192.168.1.100
ping db
eth0 TEST
PING db (192.168.1.11) 56(84) bytes of data.
64 bytes from db (192.168.1.11): icmp_seq=1 ttl=64 time=0.052 ms
64 bytes from db (192.168.1.11): icmp_seq=2 ttl=64 time=0.079 ms
192.168.1.115
cat >> /etc/hosts
192.168.1.115 test
ping test
PING test (192.168.1.115) 56(84) bytes of data.
64 bytes from test (192.168.1.115): icmp_seq=1 ttl=64 time=0.052 ms
64 bytes from test (192.168.1.115): icmp_seq=2 ttl=64 time=0.079 ms
192.168.1.10 web
192.168.1.11 db
DNS 192.168.1.12
192.168.1.20
192.168.1.21
192.168.1.22
nfs
web
db-1
nfs-1
192.168.1.30 web-1
192.168.1.31 db-2
192.168.1.32 nfs-2
192.168.1.40 web-2
192.168.1.41 sql
A eth0 192.168.1.42 web-5
192.168.1.50 web-test
192.168.1.61 db-prod
192.168.1.52 nfs-4
192.168.1.60 web-3 eth0 DNS
192.168.1.61 db-test
192.168.1.10 192.168.1.0 192.168.1.62 nfs-prod
192.168.1.116 test
cat >> /etc/hosts 192.168.1.100
192.168.1.115 test
cat /etc/nsswitch.conf
eth0 TEST
…
hosts: files dns
…
192.168.1.115
192.168.1.10 web
192.168.1.11 db
G
DNS 8.8.8.8
192.168.1.12
192.168.1.20
192.168.1.21
192.168.1.22
nfs
web
db-1
nfs-1
192.168.1.30 web-1
192.168.1.31 db-2
192.168.1.32 nfs-2
192.168.1.40 web-2
192.168.1.41 sql
A eth0 192.168.1.42 web-5
192.168.1.50 web-test
192.168.1.61 db-prod
192.168.1.52 nfs-4
192.168.1.60 web-3 eth0 DNS
192.168.1.61 db-test
192.168.1.10 192.168.1.0 192.168.1.62 nfs-prod
192.168.1.116 test
cat >> /etc/hosts 192.168.1.100
Forward All to 8.8.8.8
192.168.1.115 test
.
Root
DNS
.com
.com
DNS
google
Google
DNS
apps
216.58.221.78
Domain Names
Org
DNS
mycompany.co
m
Search Domain
192.168.1.11 db.mycompany.com
db
Org 192.168.1.12 nfs.mycompany.com
nfs
DNS
192.168.1.13 web-1.mycompany.com
web-1
192.168.1.14 sql.mycompany.com
sql
mycompany.co
m
nfs web mail drive www pay hr sql
ping web
ping web
PING web.mycompany.com (192.168.1.10) 56(84) bytes of data.
64 bytes from web.mycompany.com (192.168.1.10): … time=0.052 ms ping: web: Temporary failure in name resolution
64 bytes from web.mycompany.com (192.168.1.10): … time=0.079 ms
ping web.mycompany.com
ping web.mycompany.com
PING web.mycompany.com (192.168.1.10) 56(84) bytes of data.
PING web.mycompany.com (192.168.1.10) 56(84) bytes of data. 64 bytes from web.mycompany.com (192.168.1.10): ttl=64 time=0.052 ms
64 bytes from web.mycompany.com (192.168.1.10): ttl=64 time=0.052 ms
Record Types
A web-server 192.168.1.1
AAAA web-server 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Non-authoritative answer:
Name: www.google.com
Address: 172.217.0.132
dig
dig www.google.com
; <<>> DiG 9.10.3-P4-Ubuntu <<>> www.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28065
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.google.com. IN A
;; ANSWER SECTION:
www.google.com. 245 IN A 64.233.177.103
www.google.com. 245 IN A 64.233.177.105
www.google.com. 245 IN A 64.233.177.147
www.google.com. 245 IN A 64.233.177.106
www.google.com. 245 IN A 64.233.177.104
www.google.com. 245 IN A 64.233.177.99