Linux network basic configuration, DHCP principle and configuration

1.ip link: view data link layer information (MAC address) 2. ethtool eth0 view network interface speed, working mode (duplex mode) 3 modify the host name method:
* Temporary: hostname XX, bash (new shell interpreter) It can be displayed)
* Permanent: hostnamectl set-hostname XXX

4. IP configuration method
* Temporary: ifconfig device name short format subnet mask
* Permanent: Modify /etc/sysconfig/network-scripts/ or nmtui network management tool

5. Example of setting the network card sub-interface: ifconfig eth0:0 192.168.250.100 (temporary) 6. Restart the network service
* /etc/init.d|network restart
* systemctl restart network

7. Configure routing entries 1. Temporary:
1) Static
Add: route add -net network segment/short format mask gw gateway
Minus: route del -net network segment/short format mask gw gateway
2)
Add by default : route add default gw gateway
minus: route del default gw gateway
2. Permanent
1. CentOS6: vi /etc/rc.local (automatically boot file after booting)
CentOS7: vi /etc/rc.local or vim /etc/rc.d/rc. local
2. The default route can be added to /etc/sysconfig/network-scripts/ifcfg-ens32
3. Vi /etc/sysconfig/static-routers (static)
Example: any net 192.168.200.0/24 gw 192.168.250.254

8. Turn on the routing and forwarding function
*
temporarily: vim /proc/sys/net/ipv4/ip_foward change 0 to 1, or echo "1" >/proc/sys/net/ipv4/ip_foward
*
permanent: vim /etc/sysctl .conf is written into net.ipv4_forward=1, sysctl -p takes effect, and the cat /proc/sys/net/ipv4/ip_foward view becomes 1.

9. DNS domain name resolution settings
*
vim /etc/sysconfig/network-scripts/ifcfg-ens32, add DNS1= XXX DNS2=XXXX
*
vi /etc/resolv.conf write data, for example nameserver 192.168.250.2 (temporary)

10. Domain name resolution local host mapping file
Example: After writing 1.2.3.4 www.taobao.com in vim /etc/hosts, Taobao cannot be accessed, and the priority is higher than DNS

11. DHCP (Dynamic Host Configuration Protocol)

12.dhp lease process
Insert picture description here

* 主机发送DHCP Discover广播包(包含主机名和MAC地址),为了寻找DHCP服务器
* 

The DHCP server sends a DHCP Offer (broadcast/unicast). The DHCP server finds a free IP in the address pool, marks it, and sends it to the host by broadcast or unicast. (Windows broadcast, Unix-like is unicast)
*The
host replies to the DHCP Request broadcast packet and informs all the servers of the selected IP
* The
DHCP server sends the DHP ACK broadcast packet/but broadcast packet, and configures the IP, network segment, and gateway subnet mask for the host Code and other information.

13. An event occurs when logging in again
*
Renewal is successful: the host directly sends a DHCP Request broadcast packet to the DHCP server, the DHCP server checks the IP and can continue to use it, and just reply with the DHCP ACK packet.
*
Renewal failed: the host sends a DHCP Request broadcast packet directly to the DHCP server, the DHCP server checks that the IP is occupied and replies with a DHCP NACK, and the host restarts from sending the DHCP Discover step.

14. DHCP relay principle
Through the three-layer switch, the DHCP server is given the function of assigning IP to different networks.
Note: dhclient -r: delete the previous dhcp information dhclient -d: view the new dhcp allocation process.

15. DHCP installation and configuration
1.
Select the vmnet1 network in the virtual machine, and close the dhcp service.
2.
vim /etc/sysyconfig/network-scripts/ifcfg-ens32, modify it to static mode, and set the subnet mask and ip.
3.
Restart the network card systemctl restart network
4.
Host network card configuration, open vmnet1, set the IP and subnet mask. (Ncpa.cpl)
5.
yum -y install dhcp installation
6.
cd /etc/dhcp,cat dhcpd.conf view
7.
grep -v“^#” /usr/share/doc/dhcp-4.2.5/dhcpd. conf.example> /etc/dhcp/dhcp.conf Copy the commented out configuration items
8.
pwd and vim dhcpd.conf for configuration. As shown in the figure:

Insert picture description here
9.systemctl restart dhcpd restart function
10.netstat -anptu | grep dhcpd test

16. The required content of the network card configuration information (/etc/sysconfig/network-scripts/ifcfg-ens) is as follows: Insert picture description here
17. Common DNS
202.106.0.20
114.114.114.114
8.8.8.8
4.4.4.4

Guess you like

Origin blog.csdn.net/qq_39109226/article/details/109497462