In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
There are many commands about network configuration in CentOS6. This article will introduce several commands that are usually the longest, as well as the configuration of network card IP address and simple routing configuration.
1. The frequently used command to view the IP address is ifconfig. If you do not follow the parameters, you can view all enabled ENI information by default, as shown below:
If you want to view the information of a specific network card, you can follow the network card device after ifconfig. For example, if you only view the information of eth0, you can execute: ifconfig eht0.
Disable a network card: combined with the down command, you can disable a network card. If you want to disable an eth0 network card, you can execute: ifconfig eth0 down. This prohibition is only temporary and will be automatically enabled when the host is rebooted.
Enable a network card: use a up command to enable a network card. If eth0 is enabled, execute: ifconfig eth0 up.
The ifconfig-a command can view all Nic information, including disabled ones.
2. NetworkManager service can automatically detect the network and connect to the network automatically, which has the advantage of simplifying the work of network connection and making the desktop itself and other applications aware of the network. However, sometimes there will be problems when modifying the network by modifying the configuration file, so in most cases the service will be disabled. Disable it in the following ways:
Service NetworkManager stop # shut down the NetworkManager service
Chkconfig NetworkManager off # prohibits NetworkManager service from booting itself
3. Configure the IP address of the network card
With ifconfig configuration, the IP address configured by this method takes effect immediately, but only temporarily, and expires when the host is restarted.
Syntax: ifconfig IFACE IP/MASK [up] or ifconfig IFACE IP netmask MASK
Use the setup or system-config-network command to fall out of the graphical tool to configure the IP address. After the configuration, you need to restart the network service manually and take effect permanently after restart. The restart command is service network restart. The graphical configuration interface is as follows.
Set the IP address by modifying the configuration file, and the path of the configuration file is / etc/sysconfig/network-scripts/ifcfg-IFACE. After the modification of the configuration file, you also need to restart the network service to take effect, and take effect permanently.
The parameters in the configuration file are described:
DEVICE: the device to which this profile is applied. The device name, such as eth0, is required.
HWADDR: the MAC address of the corresponding device. If you need to modify the MAC address manually, you need to change the HWADDR to MACADDR.
BOOTPROTO: the protocol used to activate the corresponding device, such as dhcp, static, none, bootp
NM_CONTROLLED:NM is the abbreviation of NetworkManager, indicating whether this Nic is controlled by NM. It is recommended to set it to "no" in CentOS6.
ONBOOT: whether to activate this device when the system boots
TYPE: device interface type, such as Ethernet and Bridge
UUID: unique identification of the Devic
IPADDR: indicates the IP address to be set
The subnet mask of the NETMASK:IP address, which can also be expressed as "PREFIX= network bits"
GATEWAY: setting default gateway addr
DNS1, DNS2, DNS3: set the DNS server address. You can set three addresses at the same time.
USERCTL: whether the average user can control the secondary device
PEEDNS: this option is used with BOOTPROTO. If the value of BOOTPROTO is dhcp, it indicates whether the dns address assigned by DHCP is allowed to be overwritten into the / etc/reslov.conf file (which holds the DNS server address).
As shown in the following figure, what needs to be filled in the configuration file:
4. A network card can be configured with multiple IP addresses: multiple IP addresses can be bound to a network card by aliases of the network card. The aliases of the network card appear in the form of colons plus numbers, such as eht0:1, and you need to create a corresponding configuration file separately. You can set the IP address in the configuration file. The IP address must be static and cannot be obtained by DHCP. The specific setting steps are as follows:
Take binding multiple ip addresses on eht1 as an example:
Step 1: create a new configuration file, such as ifcfg-eth2:1, under the / etc/sysconfig/network-scripts/ directory, and add the necessary information, as shown below: (you need to create a corresponding configuration file for each address bound on the eth2 Nic)
Step 2: restart the network service to make it work (service network restart)
It should be noted that the primary network card can use DHCP to obtain the address automatically, but the bound ip cannot use DHCP to obtain the address. It can only set a static IP address.
5. Multiple NICs share an IP address: this method can achieve high availability or load balancing, and can be achieved through bonding. There are three working modes of bonding:
Mode0 (balance-rr): a Round-robin policy that sends packets on each Nic interface in a polling manner, which provides load balancing and fault tolerance
Mode1 (active-backup): active-backup (hot backup) policy, in which only one of the bound NICs is activated, and the others are standby. When and only if there is a problem with the active interface, another Nic interface is automatically activated.
Mode3 (broadcast): broadcast policy that forwards all messages on all bound interfaces. This mode provides fault tolerance.
Let's do bonding with eth0 and eth2, and use mode1 mode
Step 1: create a bonding configuration file under the / etc/sysconfig/network-scripts/ directory, name it ifcfg-bond0, and fill in the necessary information, as shown in the following figure
Miimon is used for link detection, if miimon=100, then the system detects the link connection status once per 100ms, and automatically transfers to another line if one line is unavailable.
Step 2: modify the configuration files of the eth0 and eth2 network cards, as shown in the following figure
SLAVE=yes: indicates that the network card is used as a backup
MASTER=bond0: indicates that the bond0 device is used as the active
Step 3: restart the network service to make it effective. After taking effect, see the following figure
You can see from the figure that the MAC addresses of the physical network cards are all the same, with eth0 as the active and eth2 as the standby
The fourth step, test, manually disconnect eht0 to see if eth2 becomes active, and then manually disconnect eth2 to see if you can automatically switch to eht0.
6. Route settings. You can manually add and delete static routes through the route command.
The command to view routes is: route-n
Add route syntax as: route add [- net |-host] target [netmask Nm] [gw Gw] [[dev] If]
In the figure below, add a route to 10.1.1.0 Compact 24, which comes out of the eth2 port, and the next hop is 192.168.1.2
The syntax for deleting a route is: route del [- net |-host] target [gw Gw] [netmask Nm] [[dev] If]
As shown in the following figure, delete a static route to the 123.10.1.0 Universe 24 network segment
By manually modifying the route above, it can be found that CentOS can act as a router to achieve the route forwarding function, but you need to enable the route forwarding function, that is, the value of / proc/sys/net/ipv4/ip_ for word is changed to 1, which can be modified by the following command:
Echo 1 > / proc/sys/net/ipv4/ip_forword
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.