IP parameter information
As we all know, if the host wants to connect to the Internet, it must set up a set of legitimate IP parameter information. These IP parameters include: IP, Netmask, Gateway, Route, DNS, host name, and so on.
Ip/netmask: It is mainly used to determine the network in which it is located, and whether the host is in the same network as the host.
Gateway:gateway is our usual gateway, which is mainly used for communication between this host and other network hosts.
Route: Create a path entry in three different types:
- Network routes reach a range of host addresses through which routes are routed for the network.
- The host route arrives at a certain host address, through the specified route, even if the host route
- The default route target is all non-local networks, usually the next hop of the default route to the gateway address of a NIC on the host computer.
DNS: Used primarily for domain name parsing.
Configuration of the NIC
Before configuring the IP parameters, let's first determine which NIC device to configure. Ifconfig This command can display the network card information of our current host, the default network card name is eth0, the second NIC name is eth1, and so on.
In the path/etc/udev/rules.d/70-persistent-net.rules is the current system's network card profile information, by modifying the configuration file "name", we can modify the name of the network card.
After modifying the NIC name in the configuration file, we need to modify the Ecfg-ethx class file to the/etc/sysconfig/network-scripts/directory, so that its "DEVICE" is consistent with the "name" of the configuration file.
"HWADDR" is consistent with the configuration file's Attr{address}, so our NIC name modification is complete.
After the configuration is complete, we need to restart the NIC driver for the modification information to take effect.
Query NIC Driver
Restart the drive for the changes to take effect
modprobe -r e1000; modprobe e1000
Set IP Address
Set static IP
There are two ways to configure IP addresses, one is to manually specify a static IP, and one is to obtain IP dynamically.
Static IP Settings We can configure the Ifconfig command, the configured IP will immediately read into the kernel, immediately effective, but not permanent, for its permanent effect, we generally choose to directly configure the corresponding network card configuration file, to obtain a permanent valid static IP
- Now I have a brand-new network card, eth2
- In the/etc/sysconfig/network-scripts/directory, create the Ifcfg-eth2 file, of course, we can directly copy the Ifcfg-eth1 file, and then modify the configuration, as follows:
Here eth1 is already configured the file, the file shows is the eth1 parameter information; Now we describe these parameters:
Device: The devices associated with this profile, whose value should normally be ifname in Ifcfg-ifname.
Type: Device types, usually with "Ethernet", "Bridge"
UUID: Unique identification code for the network card device
Onboot: Whether this device is activated with OS startup
HWADDR: MAC address of network card
Nm_controlled: Indicates whether the NIC supports NetworkManager management
Bootproto=dhcp|static|none If the row is deleted, set the address manually
Peerdns=no default is yes, when the network card is started, and Peerdns=yes, the DNS configuration file DNS will be overwritten by the network card's DNS settings, if the NIC is DHCP is overwritten by DHCP settings, if the network card is static address, then statically configured DNS overwrite
Ipv6init: Initialize the IPv6 protocol address
3. Configuring the Ifcfg-eth2 File
4. Restart the NIC driver, view eth2 IP, Setup complete
Set up auto Get IP
To get the IP address automatically, we need to rely on the DHCP service, do not need to manually increase the IP address, so we just need to open the DHCP service in the configuration file, that is, bootproto=dhcp.
Routing Management
Host interactions between the same network scope can be accomplished by broadcasting, and routing information is required to enable the interaction of hosts of different network scopes.
By the figure we can clearly understand the role of the router, The router contains two different ranges of 1.1.1.251 and 2.2.2.251, when the IP 1.1.1.1 host 1 wants to interact with the IP 2.2.2.2 host 2, he sends the interaction information to the routing, which is routed to complete the interaction of the two hosts.
例: 到达192.168.0.0/24网络,经由172.16.0.1网关:
route add -net 192.168.0.0/24 gw 172.16.0.1
到达192.168.1.124主机,经由172.16.0.1网关:
route add -host 192.168.1.1/24 gw 172.16.0.1
设定默认网关:
route add -net 0.0.0.0/24 gw 172.16.0.1 route add default gw 172.16.0.1
* 删除路由
route del [-net | -host] TARGET gw GATEWAY [dev IFNAME]
-----
Linux System IP parameter information management