centos 7.2搭建完成设置网卡

一、配置静态ip

[root@localhost ~]#  ls /etc/sysconfig/network-scripts/ifcfg-*
/etc/sysconfig/network-scripts/ifcfg-eno16777736  /etc/sysconfig/network-scripts/ifcfg-lo
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eno16777736 

默认生成的网卡配置

TYPE="Ethernet"
BOOTPROTO="dhcp"
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"
NAME="eno16777736"
UUID="bbc76d1e-2eb6-48b8-b873-3a4c767163a7"
DEVICE="eno16777736"
ONBOOT="no"

添加

BROADCAST=”192.168.0.255”
IPADDR=”192.168.0.10”
NETMASK=”255.255.255.0”
GATEWAY=”192.168.0.1”

原文改
ONBOOT=”no” #no改成yes
BOOTPROTO=”dhcp” #dhcp改成static

TYPE="Ethernet"
BOOTPROTO="static"
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"
NAME="eno16777736"
BROADCAST="192.168.0.255"
IPADDR="192.168.0.10"   ##就是静态IP
NETMASK="255.255.255.0" ##子网掩码
GATEWAY="192.168.0.1"   ##网关、路由地址
DNS1="192.168.0.1"      ##DNS可以不在这里配置
DNS2="114.114.114.114"  ##DNS可以不在这里配置
UUID="bbc76d1e-2eb6-48b8-b873-3a4c767163a7"
DEVICE="eno16777736"
ONBOOT="yes"

重启网卡
[root@localhost ~]# /etc/init.d/network restart

systemctl restart network

二、设置DNS

ping不通域名了,需要配置DNS

>#Generated by NetworkManager
>nameserver 8.8.8.8
>nameserver 114.114.114.114

如是在VM虚拟机里NAT模式下,设置一下网卡

centos 7.2搭建完成设置网卡_第1张图片
查看本机电脑的虚拟机网卡ip
centos 7.2搭建完成设置网卡_第2张图片

注意网段和网关

你可能感兴趣的:(Linux服務器)