CentOS网卡、ifconfig命令、网络相关配置文件、selinux基础、yum源

1.1网卡的命名规则
CentOS6采用连续号码命名:eth0、eth1等,当增加或删除网卡时,名称可能会发生变化
CentOS7采用dmidecode采集设备信息来命名,可以实现网卡名字永久唯一化。主板上集成的网卡命名ifcfg-ens33,PCI-E扩展槽网卡命名ifcfg-enp33
en表示以太网Ethernet,o主板板载网卡,p独立网卡PCI网卡,s热插拔网卡类似于usb,nnn:mac地址+主板信息计算得出的唯一序列

2.1ifconfig命令
[root@xuegod63 ~]# 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::20c:29ff:fe84:bb6d prefixlen 64 scopeid 0x20
ether 00:0c:29:84:bb:6d txqueuelen 1000 (Ethernet)
RX packets 47785 bytes 71015258 (67.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 17512 bytes 1070272 (1.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
参数说明:
第一行:up表示网卡开启 RUNING表示网线处于连接状态 MULTICAST支持组播 mtu(Maximum Transmission Unit) 1500表示最大传输单元大小为1500字节
第二行:网卡的IP地址、子网掩码、广播地址
第三行:IPv6的配置信息
第四行:网卡的Mac地址 ether表示连接类型为以太网 txqueuelen 1000表示传输队列的长度
第五六行:网卡接收数据包的统计信息和接收错误的统计信息
第七八行:网卡发送数据包的统计信息和发送错误的统计信息

2.2临时修改IP地址
[root@xuegod63 Desktop]# ifconfig ens33 192.168.1.110 netmask 255.255.255.0

2.3添加多个临时IP
[root@xuegod63 ~]# ifconfig ens33:0 192.168.1.110 netmask 255.255.255.0 up
[root@xuegod63 ~]# ifconfig ens33:1 192.168.1.111 netmask 255.255.255.0 up
[root@xuegod63 ~]# 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::20c:29ff:fe84:bb6d prefixlen 64 scopeid 0x20
ether 00:0c:29:84:bb:6d txqueuelen 1000 (Ethernet)
RX packets 249377 bytes 372605146 (355.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 101222 bytes 6122058 (5.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

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:84:bb:6d  txqueuelen 1000  (Ethernet)

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:84:bb:6d  txqueuelen 1000  (Ethernet)

2.4删除临时IP
[root@xuegod63 ~]# ifconfig ens33:0 del 192.168.1.110

3.1NeworkManager
NeworkManager服务是管理和监控网络设置的守护进程,CENTOS7更加注重使用NetworkManager服务来实现网络的配置和管理,7.0以前是通过network服务管理网络,以后的版本,所有网络管理和设置统一由NetworkManager服务来维护。它是一个动态的,事件驱动的网络管理服务。

3.2CentOS Redhat Linux网络相关的配置文件
[root@xuegod63 ~]# ls /etc/sysconfig/network-scripts/ifcfg-ens33 #IP地址,子网掩码等配置文件
[root@xuegod63 ~]# ls /etc/sysconfig/network-scripts/ifcfg-lo #网卡回环地址
[root@xuegod63 sysconfig]# cat /etc/resolv.conf #DNS配置文件
[root@xuegod63 sysconfig]# cat /etc/hosts #设置主机和IP绑定信息
[root@xuegod63 sysconfig]# cat /etc/hostname #设置主机名

3.3.1nmtui永久修改网卡IP地址
[root@xuegod63 Desktop]# nmtui
弹出界面后根据界面的提示进行配置即可

3.3.2修改网卡配置文件永久修改网卡IP地址
[root@xuegod63 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet #接口类型;常见有的Ethernet, Bridge
BOOTPROTO=static # 等号后面写:dhcp 表示动态获取IP地址, satic 表示表态IP,none表示不指定,就是静态。
NAME=ens33
UUID=aadf4eb9-04ef-44fc-8b14-e352783f7495 #设备的惟一标识
DEVICE=ens33
ONBOOT=yes #在系统引导时是否激活此设备
IPADDR=192.168.1.63
NETMASK=255.255.255.0
GATEWAY=192.168.1.2
DNS1=8.8.8.8
PROXY_METHOD=none
BROWSER_ONLY=no
PREFIX=24
DEFROUTE=yes
PEERDNS=no
IPV4_FAILURE_FATAL=no #如果为yes,则ipv4配置失败禁用设备
IPV6INIT=no
USERCTL:普通用户是否可控制此设备
NM_CONTROLLED: NM是NetworkManager的简写,此网卡是否接受NM控制;建议CentOS6为“no”

3.4关闭防火墙
[root@xuegod63 ~]# systemctl status firewalld.service #查看firewalld状态
[root@xuegod63 ~]# systemctl stop firewalld #关闭
[root@xuegod63 ~]# systemctl start firewalld #开启
[root@xuegod63 ~]# systemctl disable firewalld #永久关闭防火墙 //RHLE7
[root@xuegod63 ~]# chkconfig --list|grep network #查看开机是否启动 //RHLE6
[root@xuegod63 ~]# systemctl enable firewalld #开机自动启动

3.5SELinux
[root@xuegod63 ~]# getenforce #查看selinux状态
Disabled

[root@xuegod63 ~]# setenforce 0    #临时关闭selinux
setenforce: SELinux is disabled

永久关闭selinux:
[root@xuegod63 ~]# vim /etc/selinux/config  
改:7 SELINUX=enforcing     #前面的7,表示文档中第7行。方便你查找
为:7 SELINUX=disabled
[root@xuegod63 ~]# reboot

3.6设备挂载配置文件
[root@xuegod63 ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Fri Jan 25 14:56:11 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=eb373b5b-42c6-430b-b75d-b668294fb937 /boot                   xfs     defaults        0 0
UUID=fbce2ad1-609c-4936-b92c-99fc015e8511 swap                    swap    defaults        0 0


/dev/sdb1   /sdb1   xfs   defaults    0 0

3.7配置本地yum源
[root@xuegod63 yum.repos.d]# vim CentOS7.repo #写入以下红色内容
[CentOS7]
name=CentOS7
baseurl=file:///mnt
enabled=1
gpgcheck=0
[root@localhost ~]# yum clean all #清空yum缓存
[root@localhost ~]# yum list #生成缓存列表

猜你喜欢

转载自www.cnblogs.com/mrpangpang/p/12416675.html