Linux Network configuration

Source: Internet
Author: User

First step: View network Information

[Email protected] ~]# ifconfig

Ens33:flags=4163<up,broadcast,running,multicast> MTU 1500
Ether 00:0c:29:2d:4c:b4 Txqueuelen (Ethernet)
RX Packets 456 Bytes 47202 (46.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX Packets 0 Bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Lo:flags=73<up,loopback,running> MTU 65536
inet 127.0.0.1 netmask 255.0.0.0
Inet6:: 1 prefixlen ScopeID 0x10Loop Txqueuelen 1 (Local Loopback)
RX Packets 764 Bytes 68212 (66.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX Packets 764 Bytes 68212 (66.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Virbr0:flags=4099<up,broadcast,multicast> MTU 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
Ether 52:54:00:32:d4:dd Txqueuelen (Ethernet)
RX Packets 0 Bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX Packets 0 Bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

From the above information we can know that this Linux host has 3 network cards, respectively, Ens33,lo and Virbr0. Now let's introduce these 3 network cards.

ENS33: It was the former eth0, just a change of name. The reason for switching to Ens33 is to use the new features of the SYSTEMD system and change the naming rules.

Lo: is the abbreviation for localhost, which represents the native

VIRBR0: is the abbreviation for virtual network switch, which is the "VM interface".

Configure the Internet, ens33 this one NIC is enough. According to the above information, we know that ens33 not even a single IP, and now we open the configuration file of this NIC, to configure.

Step Two: Configure the network

[Email protected] ~]# Vim/etc/sysconfig/network-scripts/ifcfg-ens33 #打开配置文件

Type=ethernet
Bootproto=dhcp #改为static, which means that IP is no longer auto-acquired, but a custom setting
Defroute=yes
Peerdns=yes
Peerroutes=yes
Ipv4_failure_fatal=no
Ipv6init=yes
Ipv6_autoconf=yes
Ipv6_defroute=yes
Ipv6_peerdns=yes
Ipv6_peerroutes=yes
Ipv6_failure_fatal=no
Ipv6_addr_gen_mode=stable-privacy
Name=ens33
uuid=0e5c2bee-2596-43bf-bb9c-d51cfde65423
Device=ens33
Onboot=no #改为yes, indicating that the network adapter is loaded on boot

ipaddr=192.168.64.100 #新增的ip地址, set IP address

The reason for this configuration is 192.168.64.100: My virtual machine is connected with the real machine in NAT mode, the IP of the corresponding network card is 192.168.64.1

The following is a detailed description of the IP configuration

Device=name, where name is the name of the physical device (except for dynamically assigned PPP devices, its name is "logical name".)

IPADDR=ADDR, here addr is the IP address.
Netmask=mask, where mask is the netmask.
NETWORK=ADDR, here addr is the network address.
BROADCAST=ADDR, here addr is the broadcast address.
GATEWAY=ADDR, here addr is the gateway address.
Onboot=answer, here answer take one of the following values:
Yes-the device will be activated at boot.
No-the device is not activated at boot.
Userctl=answer, here answer take one of the following values:
Yes-non-root users can control the device.
No-the non-root user is not allowed to control the device.
Bootproto=proto, here Proto take one of the following values:
None-the boot-time protocol is not used.
BOOTP-Uses the BOOTP protocol.
DHCP--Use DHCP protocol.
The following are the values used by all PPP and slip files:

Persist=answer, here answer take one of the following values:
Yes-the device will remain active, even if the modem is hung up, causing an inactive state.
No-the device does not maintain its active state.
Modemport=port, where port is the device name for the modem port (such as "/dev/modem").
Linespeed=baud, baud is the modem's line rate (for example, "115200").
Defabort=answer, here answer take one of the following values:
Yes-Inserts the default terminating string when creating or editing a script for the interface.
No-do not insert the default terminating string when creating or editing scripts for this interface.
The following values apply to all PPP files:

Defroute=answer, here answer take one of the following values:
Yes-sets the interface as the default route.
No--do not set the interface as the default route.
Escapechars=answer, here answer take one of the following values:
Yes-use predefined asyncmap.
No-don't use a predefined asyncmap.
(This represents a simplified interface; it does not allow the user to specify that the escape character be used.) However, you can use a 00000000 Asyncmap in almost any situation, and you can set Pppoptions to use any asyncmap if you need to.)

Hardflowctl=answer, here answer take one of the following values:
Yes-use hardware flow control.
No-no hardware flow control is used.
Pppoptions=options, the options here are arbitrary option strings. It is placed at the end of the command line to overwrite the previous options (such as Asyncmap).
Papname=name, where name is part of the "name $PAPNAME" in the PPPD command line.
Note that the option "RemoteName" is always specified as a logical PPP device name, such as "Ppp0" (which could be a physical device PPP1 if other PPP devices were previously activated) to facilitate the management of PAP/CHAP files--name/ PASSWD are associated with logical PPP device names, so they can be managed together. Theoretically, it is feasible for logical PPP devices to have names other than "Ppp0"-"pppn", such as "Worldnet" or "Myisp".

REMIP=ADDR, where addr is set to the remote IP address (usually not specified)
Mtu=value, where value is the value of the MTU.
Mru=value, where value is set to the MRU value.
Disconnecttimeout=value, where value indicates how many seconds to wait to connect after a successful connection is terminated.
Retrytimeout=value, where value is the number of seconds to wait after a failed attempt to connect to make the next connection.

Step Three: Restart the network Service

[Email protected] ~]# service network restart
Restarting network (via Systemctl): [OK]

Fourth Step: View network Information

[Email protected] ~]# ifconfig
Ens33:flags=4163<up,broadcast,running,multicast> MTU 1500
inet 192.168.64.100 netmask 255.255.255.0 broadcast 192.168.64.255 #配置的ip生效了
Inet6 fe80::c5a8:b599:612a:b242 Prefixlen ScopeID 0x20<link>
Ether 00:0c:29:2d:4c:b4 Txqueuelen (Ethernet)
RX packets 2658 Bytes 206668 (201.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX Packets 511 Bytes 62256 (60.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Lo:flags=73<up,loopback,running> MTU 65536
inet 127.0.0.1 netmask 255.0.0.0
Inet6:: 1 prefixlen ScopeID 0x10Loop Txqueuelen 1 (Local Loopback)
RX packets 1132 Bytes 100052 (97.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1132 Bytes 100052 (97.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Virbr0:flags=4099<up,broadcast,multicast> MTU 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
Ether 52:54:00:32:d4:dd Txqueuelen (Ethernet)
RX Packets 0 Bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX Packets 0 Bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions

Linux Network configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.