1. Các file cấu hình:
- Network interface
- Debian-based: /etc/network/interfaces
- Red Hat-based: /etc/sysconfig/network-scripts/
- Ubuntu (>= 17.04): /etc/netplan/
- DNS server: /etc/resolv.conf
- /etc/nsswitch.conf
- Kiểm tra thông tin IP hiện tại với lệnh: ip a
khanhvc@ubutu:~$ ip a1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope hostvalid_lft forever preferred_lft forever2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000link/ether 00:0c:29:73:8d:d0 brd ff:ff:ff:ff:ff:ffinet 192.168.0.73/22 brd 192.168.3.255 scope global noprefixroute ens33valid_lft forever preferred_lft foreverinet6 fe80::9d21:bf12:41f0:7dfb/64 scope link noprefixroutevalid_lft forever preferred_lft forever4: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000link/ether 00:0c:29:73:8d:da brd ff:ff:ff:ff:ff:ffinet 192.168.0.68/22 brd 192.168.3.255 scope global dynamic noprefixroute ens38valid_lft 28788sec preferred_lft 28788secinet6 fe80::ba76:35f6:4158:5f73/64 scope link noprefixroutevalid_lft forever preferred_lft foreverkhanhvc@ubutu:~$
- Để cấu hình IP cho Ubuntu chúng ta có thể thay đổi nội dung file /etc/netplan/01-network-manager-all.yaml bằng lệnh vim
khanhvc@ubutu:~$sudo vim /etc/netplan/01-network-manager-all.yaml# Let NetworkManager manage all devices on this systemnetwork:ethernets:ens33:dhcp4: trueens38:addresses: [192.168.0.116/22]nameservers:addresses: [8.8.8.8]dhcp4: noversion: 2renderer: NetworkManager
- nhấn Esc + : wq! -> enter để lưu cấu hình và thoát khỏi vim
- Thực hiện apply cấu hình vừa thay đổi
sudo netplan apply
- Kiểm tra lại thông tin ip address
khanhvc@ubutu:~$ ip a1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope hostvalid_lft forever preferred_lft forever2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000link/ether 00:0c:29:73:8d:d0 brd ff:ff:ff:ff:ff:ffinet 192.168.0.73/22 brd 192.168.3.255 scope global dynamic noprefixroute ens33valid_lft 3560sec preferred_lft 3560secinet6 fe80::20c:29ff:fe73:8dd0/64 scope linkvalid_lft forever preferred_lft forever4: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000link/ether 00:0c:29:73:8d:da brd ff:ff:ff:ff:ff:ffinet 192.168.0.116/22 brd 192.168.3.255 scope global noprefixroute ens38valid_lft forever preferred_lft foreverinet6 fe80::20c:29ff:fe73:8dda/64 scope linkvalid_lft forever preferred_lft foreverkhanhvc@ubutu:~$
- nmtui: Giao diện đồ họa cơ bản để cấu hình network
- net-tools package:
- ethtool- ifconfig- iwconfig- route
- iproute2 package
ip: là câu lệnh phổ biến dần thay thế cho ifconfig
- Thêm IP vào interface ens38
sudo ip address add 192.168.0.117/22 dev ens38
- Xóa IP vào interface ens38
sudo ip address del 192.168.0.117/22 dev ens38
- Xem thông tin IP address bao gồm MAC address
khanhvc@ubutu:~$ ip add show1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope hostvalid_lft forever preferred_lft forever2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000link/ether 00:0c:29:73:8d:d0 brd ff:ff:ff:ff:ff:ffinet 192.168.0.73/22 brd 192.168.3.255 scope global dynamic noprefixroute ens33valid_lft 24533sec preferred_lft 24533secinet6 fe80::20c:29ff:fe73:8dd0/64 scope linkvalid_lft forever preferred_lft forever4: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000link/ether 00:0c:29:73:8d:da brd ff:ff:ff:ff:ff:ffinet 192.168.0.117/22 scope global ens38valid_lft forever preferred_lft foreverinet6 fe80::20c:29ff:fe73:8dda/64 scope linkvalid_lft forever preferred_lft foreverkhanhvc@ubutu:~$
- Hoặc cụ thể một interface
khanhvc@ubutu:~$ ip address show dev ens384: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000link/ether 00:0c:29:73:8d:da brd ff:ff:ff:ff:ff:ffinet 192.168.0.117/22 scope global ens38valid_lft forever preferred_lft foreverinet6 fe80::20c:29ff:fe73:8dda/64 scope linkvalid_lft forever preferred_lft foreverkhanhvc@ubutu:~$
- Thiết lập interface up/down
sudo ip link set ens38 down
- Kiểm tra sau khi thiết lập
khanhvc@ubutu:~$ ip address show dev ens38
4: ens38: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
link/ether 00:0c:29:73:8d:da brd ff:ff:ff:ff:ff:ff
khanhvc@ubutu:~$
sudo ip link set ens38 up
- Thiết lập default gateway là 192.168.0.7 thông qua interface ens33
sudo ip route add default via 192.168.0.7 dev ens33
- Xóa default gateway
sudo ip route del default via 192.168.0.7 dev ens33
- Kiểm tra bảng route hiện tại
khanhvc@ubutu:~$ ip route showdefault via 192.168.0.7 dev ens33 proto dhcp metric 100192.168.0.0/22 dev ens33 proto kernel scope link src 192.168.0.73 metric 100khanhvc@ubutu:~$
- Thêm route tĩnh
sudo ip route add 192.168.100.0/24 via 192.168.0.7 dev ens33
- Xóa route tĩnh
sudo ip route del 192.168.100.0/24 via 192.168.0.7 dev ens33
- Kiểm tra packet mà route đi qua. Ví xem để đến ip 8.8.8.8 sẽ đi qua route nào.
khanhvc@ubutu:~$ ip route get 8.8.8.88.8.8.8 via 192.168.0.7 dev ens33 src 192.168.0.73 uid 1000cachekhanhvc@ubutu:~$
- Kiểm tra bảng ARP
khanhvc@ubutu:~$ ip neigh192.168.0.16 dev ens33 lladdr 50:e5:49:a4:01:dd REACHABLE192.168.0.7 dev ens33 lladdr 00:d7:8f:0d:b8:3f REACHABLE192.168.0.48 dev ens33 lladdr 94:de:80:a6:fb:30 REACHABLEkhanhvc@ubutu:~$
- ping
- traceroute: ICMP
- tracepath: UDP
- host
- dig
- nslookup
- netstat
- ss
sudo apt-get install traceroute
sudo yum install traceroute
Command | Giải Thích |
---|---|
ping -c 4 google.com.vn | Ping google.com.vn với 4 gói tin |
traceroute 8.8.8.8 | Kiểm tra để đi đến được google.com.vn thì cần qua những next-hop nào |
tracepath google.com.vn | Tương tự như traceroute |
No comments:
Post a Comment