This is the 7th day of my participation in Gwen Challenge


Viewing Network Configurations

1. Run the ifconfig command to view the IP address of the network port

The network interface card of a host is usually called a “network interface”. On Linux, you can run the ifconfig command to view the IP address configuration of a network interface. If no option or parameter is specified, information about enabled network interfaces on the current host is displayed.

Eth0: the name of the first Ethernet card. The eth value in eth0 is short for Ethernet, indicating that the NIC type is Ethernet. 0 indicates the first NIC. Since most hosts have only one physical nic, eth0 represents the unique network interface in the system. If there are multiple physical nics, name THE second NIC eth1 and the third NIC eth2.

Lo: a “loopback” network interface, which is short for “loopback”. It does not represent a real network interface, but a virtual one. The default IP address is 127.0.0.1. The loopback address is usually only used for network testing on the local machine.

If you need to view information about only one network interface, use the name of the network interface as a parameter in the ifconfig command, regardless of whether the network interface is activated.

The command output shows the basic information about eth0.

  • HWaddr: indicates the MAC address of the network interface. The MAC address of a network interface cannot be changed. It is the unique hardware address of a network adapter during production.
  • Inet Addr: indicates the IP address of the network interface.
  • Bcast: indicates the broadcast address of the network where the network interface resides.
  • Mask: indicates the subnet Mask of the network interface.
  • TX and RX: indicates the number and traffic of packets sent and received by the network interface.

2. Run the hostname command to view the hostname (without adding any options or parameters).

In Linux, some network services identify hosts by their host names. If the host names are incorrectly configured, program functions may fail.

[root@localhost-181117 ~]# hostname localhost-181117 [root@localhost-181117 ~]# hostname localhost-18111716 [root@localhost-181117 ~]# bashCopy the code

3. Run the route command to view routing table entries

The routing table in Linux determines the direction of data sent from the host to other hosts and other networks, and is the key information for troubleshooting network faults. You can run the route command to view the route information of the current host. In the output result, the Destination column corresponds to the address of the target network segment, the Gateway column corresponds to the address of the next-hop router, and the Iface column corresponds to the network interface that sends data.

[root@localhost-181117 ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.231.0   *               255.255.255.0   U     1      0        0 eth0
default         bogon           0.0.0.0         UG    0      0        0 eth0
[root@localhost-181117 ~]#
Copy the code

If the destination network segment is Default, this is the Default gateway record. If the next hop is *, the target network segment is directly connected to the local host. Combined with the -n option, you can display the address in the routing record as a number.

[root@localhost-181117 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.231.0   0.0.0.0         255.255.255.0   U     1      0        0 eth0
0.0.0.0         192.168.231.2   0.0.0.0         UG    0      0        0 eth0
Copy the code

4. Run the netstat command to check the network connection

Using the netstat command, you can view the network connection status, routing table, and interface statistics of the current system. The netstat command is an effective tool to learn about the network status and troubleshoot network service faults.

  • -a: displays the network connection information of all active hosts in China.
  • -n: Displays the host address and port information in the format of numbers.
  • -r: Displays routing table information.
  • -l: displays information about monitored network connections and ports.
  • -t: Displays TCP information.
  • -u: Displays UDP information.
  • -p: displays the process id and process name associated with the network connection.

Generally, the -anpt option is used to display the information about all TCP connections in the current system in digital format. The process information is displayed. Use the “grep” command in conjunction with the pipe to filter out the specific records you want.

/ root @ localhost - 181117 ~ # netstat anpt | grep ": 22" TCP 0 0 0.0.0.0:22 0.0.0.0: * LISTEN/SSHD TCP 0 1367 to 64 192.168.231.131:22 192.168.231.1:60782 ESTABLISHED 33595/ SSHD TCP 0 0 :::22 ::* LISTEN 1367/ SSHDCopy the code

Testing the network connection

1. Run the ping command to test the network connectivity

Using the ping command, you can continuously send test packets to the destination host and display the results. Press Ctrl+C to stop the test and display the final statistics.

If the ping command fails to obtain the data packet from the destination host, the network connectivity between the local host and the destination host is faulty.

If the stability of the communication process is affected, the result of Request timeout may be frequently displayed after the ping command is used, indicating that the connection between the host and the target host times out.

2. Run the traceroute command to trace the routes of packets

Using the traceroute command, you can test which network nodes have passed between the current host and the destination host and display the connection status of each intermediate node. For nodes that cannot respond, the connection status is displayed as *.

During the network test and troubleshooting, the ping command is usually used to test the network connection with the destination host. If the network connection is faulty, the traceroute command is used to trace the middle node where the fault occurs.

3. Run the nslookup command to test DNS domain name resolution

The nslookup command is used to test domain name resolution. You only need to specify the target domain name to be resolved as the parameter.

Use network configuration commands

  • Temporary configuration: You can modify the current network address by running commands. The modification takes effect immediately.
  • Fixed configuration: A configuration file is used to store fixed network addresses. The configuration file takes effect only after the network service or the host is restarted.

1. Change the IP address and subnet mask of the NIC

Ifconfig Network interface name IP address [netmask subnet mask]

Ifconfig Network port name IP address [/ Subnet mask length]

2. Disable or activate the network interface

To temporarily disable or reactivate a specified network interface, you need to combine the Down and Up options. After a network interface is disabled, it cannot be used to connect to other hosts.

3. Add or delete routes to the specified network segment

You can add route records by route add, specify the IP address of the directory network segment by -net, and specify the IP address of the next-hop router by GW.

You can delete a route record by running route del. You need to specify the IP address of the target network segment in the route record together with the -net option.

4. Add or delete default gateway records

The commands for adding or deleting a default gateway record are similar to those for adding or deleting a static route record. However, you only need to use default to specify the target network segment. You do not need to specify the network segment address with the -net option.

Modify the network configuration file

1. Network interface configuration file

By default, the network interface configuration file is stored in the /etc/sysconfig/network-scripts/ directory in the format of ifcfg-xxx, where XXX is the name of the network interface.

[root@localhost-181117 ~]# ls /etc/sysconfig/network-scripts/ifcfg-* /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-lo [root@localhost-181117 ~] [root@localhost-181117 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 ONBOOT=yes BOOTPROTO=static IPADDR=192.168.231.131 NETMASK = 255.255.255.0 GATEWAY = 192.168.231.1Copy the code

Description and functions of the preceding configuration items

  • DEVICE: Sets the name of the network interface.
  • ONBOOT: Sets whether the network interface is activated when the Linux system starts.
  • BOOTPROTO: indicates the configuration mode of the network interface. If the value is static, the IP address specified statically is used; if the value is DHCP, the IP address is dynamically obtained through DHCP.
  • IPADDR: indicates the IP address of the network interface.
  • NETMASK: sets the subnet mask of a network interface.
  • GATEWAY: Sets the default GATEWAY address of the network interface.

2. Enable or disable network interface Settings

On RHEL, you can restart the network service or host to make the new configuration take effect after modifying the configuration file of a network interface. By default, restarting the network service will disable all network interfaces and then re-enable all network interfaces based on the configuration file.

If you want to disable or enable only one network interface, use the ifDown and IFUP scripts respectively.

3. Host name configuration file

To change the host name of the Linux operating system, modify the /etc/sysconfig/network configuration file. In this file, the “HOSTNAME” line is used to set the HOSTNAME, and the “NETWORKING” line is used to set the default enabled status of the IPv4 network.

[root@localhost-181117 ~]# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING=yes
HOSTNAME=localhost-181117
Copy the code

4. Domain name resolution configuration file

Specifies the address of the server that provides DNS resolution for this machine

The /etc/resolv.conf file records the IP address of the DEFAULT DNS server on the local host. The modification to the file takes effect immediately. In Linux, a maximum of three DNS server addresses can be specified. The first DNS server is preferred.

[root@localhost-181117 ~]# vi /etc/resolv.conf
# Generated by NetworkManager
domain localdomain
search localdomain
nameserver 192.168.231.2
Copy the code

Localhost mapping file

The /etc/hosts file records a mapping table between host names and IP addresses. It is used to store information about frequently accessed hosts. When accessing an unknown domain name, check whether there is a mapping record in the file. If no mapping record is found, query the mapping record on the DNS server.

[root@localhost-181117 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@localhost-181117 ~]#
Copy the code

Setting up the DHCP Server

Typical DHCP application mode: Assigns various network address parameters, including IP addresses, subnet masks, broadcast addresses, default gateway addresses, and DNS server addresses. Configure the network adapter to automatically obtain the IP address, and then communicate with the DHCP server to complete the automatic configuration.

1. Mount the CD-ROM

[root@localhost-181117 ~]# mount /dev/cdrom /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost-181117 ~]#
Copy the code

2. Install the DHCP service, go to the mount point, and install the software package

[root@localhost-181117 ~]# cd /mnt/Packages/ [root@localhost-181117 Packages]# rpm -ivh DHCP - 4.4.1-38. P1. El6. Centos. X86_64. RPM warning: DHCP - 4.4.1-38. P1. El6. Centos. X86_64. RPM: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:dhcp ########################################### [100%] [root@localhost-181117 Packages]#Copy the code

3. Dhcp. conf is the main configuration file. You need to manually configure the configuration file, but the path of the sample configuration file is provided in the configuration file.

[root@localhost-181117 Packages]# cd /etc/dhcp/
[root@localhost-181117 dhcp]# ls
dhclient.d  dhcpd6.conf  dhcpd.conf
[root@localhost-181117 dhcp]# vi dhcpd.conf

#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'
#
Copy the code

4. Copy the sample file to overwrite the original file.

[root@localhost-181117 DHCP]# cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf Check whether /etc/dhcp/dhcpd.conf is overwritten. yCopy the code

5. Configure the dhcp.conf file and determine the subnet segment declaration.

[root@localhost-181117 DHCP]# vi dhcpd.conf subnet 192.168.231.0 netmask 255.255.255.0 {range 192.168.231.128 192.168.231.254; Option routers 192.168.231.1; }Copy the code

6. Set the virtual channel of the DHCP server and Windows 7 client to the same mode.

Use the host keyword to specify the name of the client that needs to use the reserved address, and use the “Hardware Ethernet” parameter to specify the MAC address of the host. Use the fixed-address parameter to specify the IP address reserved for the host. Start the service or check whether the port is normal. To stop or restart the DHCP service, change restart in the command to start or stop. If the DHCP service fails to start, check the error message at the end of /var/log/messages and rectify the error as prompted.)

[root@localhost-181117 dhcp]# vi dhcpd.conf host prtsvr { hardware ethernet 00:0C:29:75:91:EC; Fixed - address 192.168.231.132; } :wq [root@localhost-181117 DHCP]# service DHCPD restart DHCPD: [yes] Starting DHCPD: [yes] [root@localhost-181117 DHCP]#Copy the code

8. Check whether the Windows client obtains an IP address.

Configuration composition of the /etc/dhcp/dhcp.conf file

In the main configuration file dhcp.conf, you can use three types of configuration: declaration, parameter, and option.

  • Declaration: describes the division of the network layout in the DHCP server. It is the logical scope of the network Settings. Common declarations are subnet and host, where the subnet declaration is used to constrain a network segment and the host declaration is used to constrain a specific host.
  • Parameter: consists of the configuration keyword and the corresponding value. It always ends with a “:”. It is usually in the specified declared range and used to set the running characteristics of the range.
  • Options: Led by “option”, followed by the specific configuration key and corresponding value, also ending with a semicolon (:), which specifies the various address parameters assigned to the client.

This section describes how to configure the DHCP service globally

To make the configuration file structure clearer, the global configuration is usually placed at the beginning of the dhcp.conf configuration file. The global configuration can be either configuration parameters or configuration options.

  • Ddns-update-style, dynamic DNS update mode. Used to set the dynamic UPDATE mode of DNS data associated with the DHCP service. In actual DHCP applications, this parameter is rarely used. Set the value to None.
  • Default-lease -time: specifies the default lease time. The unit is second, which indicates the default time when the client can rent an IP address from the DHCP server.
  • Max-lease -time: indicates the maximum lease time allowed by the DHCP client. If the client does not request a specific lease time, the server adopts the default lease time.
  • Option domain-name: indicates the default search area. Specify the default search field for resolving host names for the client, and the option to change the configuration is reflected in the client’s /etc/resolv.conf configuration file.
  • Option domain-name-servers: specifies the DNS server address for resolving domain names for the client. This configuration option is also reflected in the /etc/resolv.conf configuration file of the client. If multiple DNS server addresses need to be set, separate them using commas (,).

Original is not easy, if you think this article is useful to you, please kindly like, comment or forward this article, because this will be my power to output more high-quality articles, thank you!

See you next time!