View network Configuration
Ifconfig command: View active network Interface Device information
Ifconfig eth*: View specified network interface device information
If eth0 represents the first Ethernet card; eth1 represents the second Ethernet card;
Hostname command: View host name
Route command: View route table entry
-N Displays the address in the routing record as a digital form, speeding up the execution speed
Netstat command: View network connection Status
-A displays network connection information for all active in the current host
-n Displays the associated host address, port, and other information in digital form
-R Display Routing table information
-l Display network connection and port information in listening state
-T view TCP protocol-related information
-U view UDP protocol Related information
-P Displays the process number, process name information associated with the network connection
Test network connection
ping command: Test the connectivity of the network
traceroute command: Trace the routing path of the packet, the network node passed
More accurate positioning of the network connection's point of failure than the ping command, which is slower than the ping command
nslookup command: Test DNS domain name resolution
such as:# nslookup yangshufan.blog.51cto.com
Set Network Address Parameters
In Linux, manually modifying the network configuration consists of two basic methods
Temporary configuration: directly modifies the network address currently in use via the command line, which takes effect immediately after the change, but fails after restarting the network service or restarting the host
Fixed configuration: The configuration file to hold a fixed variety of network address, need to restart the network service or restart the host before it takes effect. The configuration method is relatively complex, equivalent to a permanent configuration, typically used when a fixed network address needs to be set for the server
I. Configuring network Parameters with commands
Modify the address and status of the network card
Command format: Ifconfig network interface name IP address Subnet mask (default is used when no subnet mask is specified)
For example, set the IP address of the NIC Eth0 to 192.168.1.1
# ifconfig eth0 192.168.1.1/24
disabling, enabling network interfaces
For example: Disable NIC eth0 First, then enable NIC Eth1
# ifconfig eth0 down
# ifconfig eth1 up
Bind a virtual interface to a network card (equivalent to a NIC with multiple IP addresses)
For example: Add a virtual interface eth0:0 for the NIC Eth0 and set the virtual interface address to 192.168.1.1, both the original address and the virtual address can be used normally
# ifconfig eth0:0 192.168.1.1
You can also add more virtual interfaces, such as Eth0:1, Eth0:2
Add, delete, default gateway records
For example: Add the default gateway 192.168.1.254 first, delete the
# route Add default GW 192.168.1.254
# route del default GW 192.168.1.254
Adding and removing static route records
For example: Add the route entry for the 192.168.3.0/24 network segment first, and the next hop address is 192.168.1.1, in the delete
-net Specify destination segment address
GW Specifies the IP address of the next-hop router
# route add-net 192.168.3.0/24 GW 192.168.1.1
# route Del-net 192.168.3.0/24
Modify the name of the host
For example, to change the host name to Yangshufan
# hostname Yangshufan
Second, modify the network configuration file
1. Network Interface configuration file
The default is in directory/etc/sysconfig/network-scripts/and the file format is ifcfg-eth*
For example: Set eth0 permanent IP address to 192.168.1.200, Gateway 192.168.1.2,dns to 202.106.0.20
# Vim/etc/sysconfig/network-scripts/ifcfg-eth0
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/9D/4B/wKioL1l9mtPDsNuBAAAwa7p6mnk747.jpg-wh_500x0-wm_ 3-wmp_4-s_148771107.jpg "title=" Alibaba picture 20170730163942.jpg "alt=" Wkiol1l9mtpdsnubaaawa7p6mnk747.jpg-wh_50 "/>
DEVICE: Set the network interface name
Onboot: Set whether to activate when Linux system starts
Bootproto: Static IP is used when the value is NULL, DHCP dynamically obtains IP
Ipaddr:ip Address
NETMASK: Subnet Mask
Gateway: Default Gateways
DNS1: Preferred DNS server address, DNS2 indicates alternate DNS server address
2. Enable and disable network interface configuration
After you modify the network interface profile, you also need to restart the networking service or reboot the host to take effect
# Service Network Restart
If you want to disable or enable only one network interface, you can control the script using two interfaces respectively.
# ifdown Eth0
# ifup Eth0
3. Host name configuration file
For example, to change the host name to Www.yangshufan.com
# vim/etc/sysconfig/network
NETWORKING = yes
HOSTNAME = www.yangshufan.com
4. Domain Name resolution configuration file
(1) Specify a DNS resolution server address for this machine
In addition to changing the network configuration file, you can also modify the/etc/resolv.conf file, the changes to the file will take effect immediately
Example: Specify a default DNS server address of 202.106.0.20 and 202.106.46.151
# Search Www.yangshufan.com
# nameserver 202.106.0.20
# nameserver 202.106.46.151
(2) Local Host mapping file
/etc/hosts file records the host name and IP address mapping table, improve the Internet speed
For example: the mapping table has "119.75.218.70 www.baidu.com" records, when accessing www.baidu.com, will send a Web request directly to 119.75.218.70, omitting the process of resolving IP address to the DNS server
# vim/etc/hosts
119.75.218.70 www.baidu.com
Using DHCP to dynamically configure host addresses
The relevant theory of DHCP has been explained in detail in the Windows Network Service, the following describes the process of building a DHCP server in Linux, using a DHCP client
Configuring the DHCP server
1. Installing the DHCP server Software
Mount the Linux system CD and install the dhcp-4.1.1-* * *. RPM PACKAGE
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/9D/4C/wKiom1l9q62yaKKfAADgpqDCJDc620.jpg-wh_500x0-wm_ 3-wmp_4-s_1597608161.jpg "title=" Alibaba picture 20170730175127.jpg "alt=" Wkiom1l9q62yakkfaadgpqdcjdc620.jpg-wh_50 "/>
2. Setting up the master configuration file
The primary configuration file for the DHCP service is/etc/dhcp/dhcp.conf, which does not include any valid configuration by default and requires an administrator to establish it manually, referring to the profile
# vim/etc/dhcp/dhcp.conf
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/9D/4D/wKiom1l9rvrwrjtUAABFlZUno7g543.jpg-wh_500x0-wm_ 3-wmp_4-s_2352774002.jpg "title=" Alibaba picture 20170730180541.jpg "alt=" Wkiom1l9rvrwrjtuaabflzuno7g543.jpg-wh_50 "/>
(1) Determine the global configuration of the DHCP service
For example, you need to build a DHCP server for the LAN, all network segments using the same lease 6 hours, the maximum lease 12 hours, the default search domain for the Yangshufan.com,dns server is 202.106.0.20 and 202.106.46.151
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/9D/4D/wKiom1l9sqvQ7arcAABm2-M2snw007.jpg-wh_500x0-wm_ 3-wmp_4-s_193162722.jpg "title=" Alibaba picture 20170730182124.jpg "alt=" Wkiom1l9sqvq7arcaabm2-m2snw007.jpg-wh_50 "/>
(2) Determine subnet network segment statement
A DHCP server can serve multiple network segments, so the subnet network segment declaration must have and can have multiple
For example, you need to service a 192.168.1.0 network segment: Address pool 1.100---1.200, default gateway 192.168.1.254
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/9D/4D/wKioL1l9t1qx7f5fAAA6LiuWyFQ548.jpg-wh_500x0-wm_ 3-wmp_4-s_3855614706.jpg "title=" Alibaba picture 20170730184118.jpg "alt=" Wkiol1l9t1qx7f5faaa6liuwyfq548.jpg-wh_50 "/>
(3) Confirm host declaration (optional)
Network properties for a single host, typically assigning a fixed IP address (reserved address) to individual servers, guaranteeing service stability
For example, assign a fixed IP address for the print server Yangshufan (MAC address of 08:00:07:26:c0:a5) 192.168.1.88
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M00/9D/4D/wKiom1l9uajhkkpgAAAqwjCpnvs137.jpg-wh_500x0-wm_ 3-wmp_4-s_1248976788.jpg "title=" Alibaba picture 20170730185116.jpg "alt=" Wkiom1l9uajhkkpgaaaqwjcpnvs137.jpg-wh_50 "/>
3. Start the DHCPD service
# service DHCPD start
Using DHCP clients
The acquisition address of the Windows client is not said, in Linux, just modify the network card configuration file for DHCP, and then restart the network card service is OK
# Vim/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE = eth0
Onboot = yes
Bootproto = DHCP
# Service Network Restart
Re-fetch the new IP address for the NIC Eth0 and display the get process
# dhclient-d Eth0
Release the acquired IP lease
# dhclient-r Eth0
Detailed information about the IP address assignment of the server can be obtained through the lease file
# less/var/lib/dhcpd/dhcpd.leases
This article is from the "Yang Shufan" blog, make sure to keep this source http://yangshufan.blog.51cto.com/13004230/1952132
Linux Basic Network Configuration