When we installed a linux system, the first thing we do, what is it, of course, is our operating system configured network, no network our servers like a lump of scrap metal, can not provide service to others, so before we configure linux network under the relevant knowledge to understand the linux network
1.1 Linux network concepts and methods to modify the IP address
1.1.1 naming card
CENTOS6 card named: it will change rather than a unique and fixed according to the situation, before CENTOS6, network interface uses a serial number name: eth0, eth1, etc., when adding or removing the card, the name may change
CENTOS7 using dmidecode collection naming scheme, in order to obtain information on the motherboard; it can achieve a permanent unique name of the network card (dmidecode This command can gather information about the hardware aspects)
Network devices are named:
1) If the index information Firmware (firmware) or BIOS-based onboard device provided available and the predictable be named according to the index, for example: ifcfg-ens33
2) If the index information Firmware (firmware) or BIOS as PCI-E available expansion slot is provided, and can be predicted, are named according to the index, for example, name, for example: ifcfg-enp33
3) If the physical position information of the available hardware interfaces, this information is named, e.g. enp2s0
The above are available, the use of conventional naming scheme.
Extended:
In CENTOS7, en represents: ethernet Ethernet is that we now use LAN
enX (X common are the following three types):
o: motherboard onboard LAN device integrated device index number. in case
p: independent card, PCI card
s: hot swap card index, usb like, expansion slot
NNN (figures) represented by: MAC address of + motherboard unique sequence information calculated
1.1.2 ifconfig command to use
Note: The operation of the root user (dynamic modification)
Command: ifconfig
Action: to configure the network or the network interface displays the current status
[root@test ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.63 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::c09d:975d:89cd:fd3f prefixlen 64 scopeid 0x20<link> ether 00:0c:29:02:83:db txqueuelen 1000 (Ethernet) RX packets 3255 bytes 4458479 (4.2 MiB) RX errors 0 dropped 26 overruns 0 frame 0 TX packets 1130 bytes 81645 (79.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
The figure illustrates information about:
The first line: up -> network card on state
RUNNING -> network connection state linework
MULTICAST -> Multicast Support
mtu 1500 -> (Maximum Transmission Unit) maximum transmission unit size is 1500 bytes
Second row: IP address, subnet mask, broadcast address
Third row: IPV6 configuration information
Fourth row: MAC address of the network card
ether indicates that the connection type is Ethernet
txqueuelen 1000 - "transmit queue length
Fifth six lines: statistics and receiving card receive a packet error statistics
Seventh eight lines: Statistical information card that sent the packet and send the error statistics
1.1.3 temporary IP address changes
Method 1: temporarily modify the network card IP address
ifconfig name of the NIC IP address --- directly modify the IP address of the network card, failed to restart
[root@test Desktop]# ifconfig ens33 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.63 netmask 255.255.255.0 broadcast 192.168.1.255 [root@test Desktop]# ifconfig ens33 192.168.1.110 netmask 255.255.255.0
Description: After modifying current terminal will eventually break, need to use a new IP address to connect
[root@xuegod63 Desktop]# ifconfig ens33 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.110 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::20c:29ff:fee8:ac4 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:e8:0a:c4 txqueuelen 1000 (Ethernet) RX packets 2028 bytes 198715 (194.0 KiB) Errors the RX 0 Dropped 0 overruns 0 Frame 0 the TX packets 385 bytes 51073 ( 49.8 KiB) the TX errors 0 Dropped 0 overruns 0 Carrier 0 Collisions 0 [root @ test Desktop] # systemctl the restart Network // card CENTOS7 restarting method of [root @ test Desktop] # the restart-Service Network // card CENTOS6 restarting method of [@ Test the root Desktop] # the ifconfig ens33 ens33: the flags = 4163 <the UP, BROADCAST, the RUNNING, the MULTICAST> MTU1500 inet 192.168.1.63 netmask 255.255.255.0 broadcast 192.168.1.255
Method 2: Add the number of temporary IP addresses
ifconfig NIC name: 0 first IP address (netmask subnet mask) --- add an IP
ifconfig NIC Name: 1 second IP address (netmask subnet mask) --- add an IP
[root@test ~]# ifconfig ens33:0 192.168.1.110 netmask 255.255.255.0 up [root@test ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.63 netmask 255.255.255.0 broadcast 192.168.1.255 ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.110 netmask 255.255.255.0 broadcast 192.168.1.255 ether 00:0c:29:e8:0a:c4 txqueuelen 1000 (Ethernet)
Delete the temporary IP
[root@test ~]# ifconfig ens33:0 del 192.168.1.110 [root@test ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.103 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::20c:29ff:fee8:ac4 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:e8:0a:c4 txqueuelen 1000 (Ethernet) RX packets 3056 bytes 311813 (304.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 961 bytes 145297 (141.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.111 netmask 255.255.255.0 broadcast 192.168.1.255 ether 00:0c:29:e8:0a:c4 txqueuelen 1000 (Ethernet)
1.1.4 NeworkManager Overview
NeworkManager service is a daemon to manage and monitor the network settings, CENTOS7 pay more attention to the use of NetworkManager services for configuration and management of the network, 7.0 previously by network service management network, future versions, all network management and set up a unified maintained by NetworkManager service . It is a dynamic, event-driven network management services.
[Root @ test ~] # systemctl status NetworkManager # networkmanager see whether the service is started
1.1.5 RHEL / CENTOS Linux network related configuration files
RHEL / CENTOS network related configuration files path:
[root @ test ~] # ls / etc / sysconfig / network-scripts / ifcfg- ens33 # IP address, subnet mask, etc. Profile [the root Test @ ~] # LS / etc / sysconfig / Network-scripts / in ifcfg- lo # NIC loopback address [root @ test sysconfig] # CAT / etc / resolv.conf #DNS configuration file [root @ test sysconfig] # CAT / etc / hosts # set the host and IP binding information [root @ test sysconfig] # CAT / etc / hostname set the hostname #
1.1.6 permanently modify the network card address:
[root@test Desktop]# nmtui
Note: Move the cursor to the bottom and click "OK" to save.
Restart card services to take effect:
[Root @ test ~] # systemctl restart network --- restart the service
Method 2: to change the IP address by modifying the card configuration file
vim shortcuts:
i: enter insert mode
Save: press esc, and then enter: wq
[root@test ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet BOOTPROTO=none # 等号后面写:dhcp 表示动态获取IP地址, satic 表示表态IP,none表示不指定,就是静态。 DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no NAME=ens33 #网卡名 UUID=50eff37c-72b4-407a-a3ee-9ef8ca746b95 DEVICE=ens33 ONBOOT=yes DNS1=8.8.8.8 DNS2=192.168.1.1 NETMASK=255.255.255.0 IPADDR=192.168.1.222 PREFIX=24 GATEWAY=192.168.1.1 IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_PRIVACY=no
参数说明:
DEVICE:此配置文件应用到的设备
HWADDR:对应的设备的MAC地址
BOOTPROTO:激活此设备时使用的地址配置协议,常用的dhcp, static, none,bootp
NM_CONTROLLED: NM是NetworkManager的简写,此网卡是否接受NM控制;建议CentOS6为“no”
ONBOOT:在系统引导时是否激活此设备
TYPE:接口类型;常见有的Ethernet, Bridge
UUID:设备的惟一标识
IPADDR:指明IP地址
NETMASK:子网掩码
GATEWAY: 默认网关
DNS1:第一个DNS服务器指向
DNS2:第二个DNS服务器指向
USERCTL:普通用户是否可控制此设备
IPV4_FAILURE_FATAL 如果为yes,则ipv4配置失败禁用设备
1.2 关闭防火墙并设置开机开不启动
查看当前状态
[root@test ~]# systemctl status firewalld.service #查看firewalld状态 [root@test ~]# systemctl stop firewalld #关闭 [root@test ~]# systemctl start firewalld #开启 [root@test ~]# systemctl disable firewalld #开机自动关闭 //RHLE7 [root@test ~]# chkconfig --list|grep network #查看开机是否启动 //RHLE6 [root@test ~]# systemctl enable firewalld #开机自动启动
2.3 临时和永久关闭Selinux
临时关闭
[root@test ~]# getenforce Enforcing [root@test ~]# setenforce 0 setenforce: SELinux is disabled
永久关闭
[root@test ~]# vim /etc/selinux/config 改:7 SELINUX=enforcing #前面的7,表示文档中第7行。方便你查找 为:7 SELINUX=disabled [root@test ~]# reboot
1.4 设置系统光盘开机自动挂载
[root@test ~]# vim /etc/fstab #在文档最后,添加以一下红色内容: /dev/cdrom /mnt iso9660 defaults 0 0 [root@test ~]# mount -a mount: /dev/sr0 写保护,将以只读方式挂载 [root@test ~]# ls /mnt/ #可以查看到此目录下有内容,说明挂载成功 CentOS_BuildTag GPL LiveOS RPM-GPG-KEY-CentOS-7
1.5 配置本地YUM源
yum的一切配置信息都储存在一个叫yum.repos.d的配置文件中,通常位于/etc/yum.repos.d目录下
删除原有的文件
[root@test yum.repos.d]#rm -rf /etc/yum.repos.d/*
创建一个新的yum源配置文件,yum源配置文件的结尾必须是.repo
[root@test yum.repos.d]# vim CentOS7.repo #写入以下红色内容 [CentOS7] name=CentOS-server baseurl=file:///mnt enabled=1 gpgcheck=0 参数说明: [CentOS7] --->yum的ID,必须唯一 name=CentOS-server ----->描述信息 baseurl=file:///mnt -------> /mnt表示的是光盘的挂载点 . file:后面有3个/// enabled=1 ------>启用 gpgcheck=0 ---->取消验证 清空并生成缓存列表 [root@localhost ~]# yum clean all #清空yum缓存 [root@localhost ~]# yum list #生成缓存列表 验证一下 [root@test yum.repos.d]# yum -y install httpd
1.6 创建可用实验快照
今天的虚拟机是真正可以使用的环境,为了保证后期误操作可能导致不可用的情况,所以要做一个快照,方便到时直接恢复到当前可用情况。
具体步骤如下:
虚拟机----》快照----》拍摄快照----》自定义快照名如“可用实验快照”