从零开始学Linux-第二天网卡基本配置说明

上篇回顾

  1. 安装 Centos 7操作系统及简单配置网络
  2. 简单介绍下Linux网络相关概念和上篇说过的修改IP地址的方法
    2.1 网卡的命名规则
    CENTOS6的网卡命名方式:它会根据情况有所改变而非唯一且固定,在CENTOS6之前,网络接口使用连续号码命名: eth0、 eth1等,当增加或删除网卡时,名称可能会发生变化。
    CENTOS7采用dmidecode采集命名方案,以此来得到主板信息;它可以实现网卡名字永久唯一化。(dmidecode这个命令可以采集有关硬件方面的信息)
    对网络设备的命名方式:
    1. 如果Firmware(固件)或BIOS为主板上集成的设备提供的索引信息可用,且可预测则根据此索引进行命名,例如: ifcfg-ens33

    2. 如果Firmware(固件)或BIOS为PCI-E扩展槽所提供的索引信息可用,且可预测,则根据此索引进行命名,例命名,例如:ifcfg-enp33

    3. 如果硬件接口的物理位置信息可用,则根据此信息进行命名,例如enp2s0
      上述均不可用时,则使用传统命名机制。
      扩展:在Centos 7中,en表示:ethernet以太网,就是使用的局域网
      enX(常见的有下面3中类型):
      o:主板板载网卡,集成设备的设备索引号。
      p:独立网卡,PCI网卡
      s:热插拔网卡
      nnn(数字表示):MAC地址+主板信息计算得出唯一的序列

    4. 可以使用ifconfig来配置或显示当前网络接口的状态

      [root@localhost ~]# ifconfig 
      ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
              inet 192.168.61.130  netmask 255.255.255.0  broadcast 192.168.61.255
              inet6 fe80::a7ad:79d1:d68d:1b18  prefixlen 64  scopeid 0x20<link>
              ether 00:0c:29:0a:8f:18  txqueuelen 1000  (Ethernet)
              RX packets 26042  bytes 11986285 (11.4 MiB)
              RX errors 0  dropped 0  overruns 0  frame 0
              TX packets 4905  bytes 719471 (702.6 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 128  scopeid 0x10<host>
              loop  txqueuelen 1000  (Local Loopback)
              RX packets 82  bytes 7126 (6.9 KiB)
              RX errors 0  dropped 0  overruns 0  frame 0
              TX packets 82  bytes 7126 (6.9 KiB)
              TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
      

      信息大概说明:
      ens33
      第一行:
      UP :网卡开启状态。
      RUNNING :网线处于连接状态。
      MULTICAST :支持组播。
      mtu 1500 :Max Transmission Unit,最大传输单元大小为1500字节。
      第二行:该网卡的IP地址,子网掩码,广播地址。
      第三行:IPV6的配置信息。
      第四行:网卡的MAC地址。ether表示连接类型为以太网,txqueelen 1000 传输队列的长度
      第五六行:网卡接收数据包的统计信息和接收错误的统计信息。
      第七八行:网卡发送数据包的统计信息和发送错误的统计信息。

      临时修改IP地址
      方法1:ifconfig 网卡名称 ip地址 netmask 子网掩码(直接修改网卡的IP地址,重启失效)
      需要注意的是:修改后当前登录的终端会中断,需要重新使用新的IP地址进行连接。

      [root@localhost ~]# ifconfig ens33 192.168.61.131 netmask 255.255.255.0
      [root@localhost ~]# ifconfig ens33
      ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
      inet 192.168.61.131  netmask 255.255.255.0  broadcast 192.168.61.255
      inet6 fe80::a7ad:79d1:d68d:1b18  prefixlen 64  scopeid 0x20<link>
      ether 00:0c:29:0a:8f:18  txqueuelen 1000  (Ethernet)
      RX packets 27947  bytes 12136751 (11.5 MiB)
      RX errors 0  dropped 0  overruns 0  frame 0
      TX packets 5328  bytes 793857 (775.2 KiB)
      TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
      #Centos 7 重启网卡的方法
      [root@localhost ~]#systemctl restart network
      #Centos 6 重启网卡的方法
      [root@localhost ~]#service network restart
      
    5. 网络相关的配置文件

      [root@localhost ~]#ls /etc/sysconfig/network-scripts/ifcfg-ens33	#ip地址,子网掩码
      [root@localhost ~]#ls /etc/sysconfig/network-scripts/ifcfg-lo		#网卡回环地址文件
      [root@localhost ~]#cat /etc/hostname								#设置主机名的配置文件
      [root@localhost ~]#cat /etc/hosts									#设置主机和IP绑定
      [root@localhost ~]#cat /etc/resolv.conf								#DNS配置文件
      
    6. 开启关闭防火墙并配置开机启动与否

      [root@localhost ~]#systemctl status firewalld			#查看防火墙状态
      [root@localhost ~]#systemctl stop firewalld				#关闭防火墙
      [root@localhost ~]#systemctl start/restart firewalld 	#开启或重启防火墙
      [root@localhost ~]#systemctl disable firewalld			#关闭开机启动
      [root@localhost ~]#systemctl enable firewalld 			#开启开机启动
      [root@localhost ~]#systemctl is-enabled	firewalld		#查询是否开机启动
      
    7. 临时和永久关闭Selinux

      #临时关闭
      [root@localhost ~]# getenforce 		#查询Selinux状态
      Enforcing
      [root@localhost ~]# setenforce 0	#设置临时关闭Selinux
      Permissive
      #永久关闭:永久关闭需要重启系统才能生效
      [root@localhost ~]#sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
      [root@localhost ~]# cat /etc/selinux/config 
      
      # This file controls the state of SELinux on the system.
      # SELINUX= can take one of these three values:
      #     enforcing - SELinux security policy is enforced.
      #     permissive - SELinux prints warnings instead of enforcing.
      #     disabled - No SELinux policy is loaded.
      SELINUX=disabled
      # SELINUXTYPE= can take one of three values:
      #     targeted - Targeted processes are protected,
      #     minimum - Modification of targeted policy. Only selected processes are protected. 
      #     mls - Multi Level Security protection.
      SELINUXTYPE=targeted 
      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值