Linux-Network Settings and DHCP Configuration

One, network settings

1. How to set network parameters

1. Temporary configuration-use commands to adjust the network parameters
Simple and fast, you can directly modify the running network parameters-generally only suitable for use in the process of debugging the network After the
system is restarted, the modifications made will be invalid
2. Fixed settings —Modify network parameters through configuration files Modify the configuration files of
various network parameters
Suitable for use when setting fixed parameters for the server It
will take effect after reloading the network service or restarting

2. Set the route record route

1. Add to the route record of the specified network segment
route add -net network segment address gw IP address
2. Delete the route record to the specified network segment
route del -net network segment address
3. Port add the default gateway record to the routing table
route add default gw IP address
4. Delete the default gateway record in the routing table
route del default gw IP address

3. Domain name resolution configuration file

1. The /etc/resolv.conf file
saves the IP address of the DNS server that the machine needs to use
2. Example
vimetc/resotv.conmf
search localdomain
nameserver 202.106.0.20
ammeserver 202.106.140.1
3. Note: CentOS 7 needs to be in the NetworkManager.conf file Set dns=none in the main section, and
restart the NetworkManager service, or use the newly added nmcli command in CentOS 7 to set it

4. Local host mapping file

1. The /etc/hosts file
saves the mapping record of the host name and the IP address
2. Example
cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.119.75.218.70 www.baidu.com
3. The host file and DNS server Comparison
By default, the system first
finds the resolution record from the hosts file. The ohosts file is only valid for the current host. The
ohosts file reduces the DNS query process and speeds up access.

Two, DHCP principle and configuration

5. DHCP service

1. DHCP (Dynamic Host Configuration Protocol)
2. Designed and developed by the Internet Task Force
3. A protocol specifically used to automatically assign TCP/IP parameters to computers in a TCP/IP network
Insert picture description here

2. DHCP lease process

The process by which the client obtains the IP address from the DHCP server is called the DHCP lease process. It is
divided into four steps
(1) the client searches for the server in the network
(2) the server responds to the client service
(3) the client sends a service to the target server Request
(4) The server provides services to the client
Insert picture description here

3. Use DHCP to dynamically configure the host address

1. DHCP service
automatically allocates addresses for a large number of clients, provides centralized management,
reduces management and maintenance costs, and improves network configuration efficiency
. 2. The address information that can be allocated mainly includes
the IP address of the network card, the subnet mask, the
corresponding network address, and the broadcast address
Default gateway address
DNS server address

2. Example: Configure DHCP server

1. Set up the virtual network editor

Shut down the dhcp service of VMnet1
Insert picture description here

2. Configure the network address

Set VMware1
Set ipv4 version
Use fixed ip address
Modify virtual machine ens33 configuration
Insert picture description here
Insert picture description here

3. Install the dhcp software package

yum install -y dhcp-install
cd /etc/dhcp/
-enter the directory ls-view
less dhcpd.conf-view details
Insert picture description here

4. Backup

cd /usr/share/doc/dhcp-4.2.5/-enter the directory
cp /usr/share/doc/dhcpd.conf.example /etc/dhcp/dhcpd.conf-copy
ls-view
vim /etc/ dhcp/dhcpd.conf-edit
systemctl start dhcpd-start
netstat -naup | grep 67-view udp protocol
Insert picture description here

5. Edit dhcpd.conf


#Set the global configuration parameter default-lease-time 600;——The default lease is about 10 minutes, in seconds
max-lease-time 7200;——The maximum lease is about 2 hours, in seconds
option domain-name “benet.com” -Specify the default domain name
option domain-name-servers 202.106.0.20, 202.106.148.1;-Specify the DNS server address
ddns-update-style none;-Disable DNS dynamic update
Insert picture description here

#subnet network segment statement (acting on the entire subnet segment, some configuration parameters have higher priority than global configuration parameters)
subnet 192.168.100.0 netmask 255.255.255.0 ——Declare the network segment address to be allocated
range 192.168.100.10 192.168.100.20—— Set the address pool
option routers 192.168.100.254——Specify the default gateway address
Insert picture description here
#host host statement (assign a fixed IP address to a single machine)
host hostname {
#Specify the name of the client that needs to be assigned a fixed IP address hardware ethernet 00:c0: c3: 22 :46:81;
#Specify the MAC address of the host fixed-address 192.168.100.188; #Specify the IP address reserved for the host
# The following content can be deleted
Insert picture description here
systemctl start dhcpd
systemctl stop firewalld
setenforce o
netstat -anpu l grep ":67 "

#If the DHCP service fails to start, you can view the log file vim /var/log/messages
Insert picture description here

6. Configure dhcp relay in eNSP

Insert picture description here
LSW1
[Huawei]dis current-configuration

vlan batch 10 20 100

interface Ethernet0/0/1
port link-type access
port default vlan 10

interface Ethernet0/0/2
port link-type access
port default vlan 20

interface Ethernet0/0/3
port link-type trunk
port trunk allow-pass vlan 2 to 4094

interface Ethernet0/0/4
port link-type access
port default vlan 100

LSW2
[Huawei]dis current-configuration

vlan batch 10 20 100

dhcp enable

interface Vlanif10
ip address 192.168.10.254 255.255.255.0
dhcp select relay
dhcp relay server-ip 192.168.100.20

interface Vlanif20
ip address 192.168.20.254 255.255.255.0
dhcp select relay
dhcp relay server-ip 192.168.100.20

interface Vlanif100
ip address 192.168.100.254 255.255.255.0
dhcp select relay
dhcp relay server-ip 192.168.100.20

interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 2 to 4094
Insert picture description here
Insert picture description here
ipconfig /release
ipconfig /renew

Guess you like

Origin blog.csdn.net/s15212790607/article/details/113862136