1、 ifconfig查看当前网卡名称
[root@centos7 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.32.128 netmask 255.255.255.0 broadcast 192.168.32.255
inet6 fe80::fde7:2dd5:97b1:a7c7 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:03:c3:41 txqueuelen 1000 (Ethernet)
RX packets 306442 bytes 405240153 (386.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 127058 bytes 11916470 (11.3 MiB)
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 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
centos7网络配置文件在/etc/sysconfig/network-scripts目录下,ens33网卡对应的配置文件为ifcfg-ens33。使用vi编辑该文件如下:
[root@centos7 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static" # 使用静态IP地址,默认为dhcp
IPADDR="192.168.241.100" # 设置的静态IP地址
NETMASK="255.255.255.0" # 子网掩码
GATEWAY="192.168.241.2" # 网关地址
DNS1="192.168.241.2" # DNS服务器
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="95b614cd-79b0-4755-b08d-99f1cca7271b"
DEVICE="ens33"
ONBOOT="yes" #是否开机启用
2、修改保存后,使用service network restart命令使静态IP地址生效
附录:
1、配置hostname的方法为 hostnamectl set-hostname (mini1)
2、配置IP地址映射域名为 vi /etc/hosts
网友评论