Centos7配置静态ip

小编接下来介绍一下centos7 虚拟机如何进行配置静态ip和mac地址
1.首先找到我们本电脑的MAC地址:
Centos7配置静态ip_第1张图片
2.记住此处的mac地址,下面要进行使用

运行命令 ip addr进行查看我们虚拟机的网卡信息

[root@cent01 network-scripts]# ip addr
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:99:33:a0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.52.140/24 brd 192.168.52.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::4fbe:8c7e:a952:cfff/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: virbr0:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:c2:7f:98 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic:  mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:c2:7f:98 brd ff:ff:ff:ff:ff:ff

我们这里是使用的是第二块网卡进行的配置:

cd /etc/sysconfig/network-scirpts

执行命令:

vim ifcfg-ens33

进行如下的配置:

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
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="cba925bc-8e15-4930-9982-8098133683d7"
HWADDR=00:0C:29:99:33:A0
DEVICE="ens33"
ONBOOT="yes"
IPADDR=192.168.52.140
GATEWAY=192.168.52.10
NETMASK=255.255.255.0
DNS1=8.8.8.8

这里主要修改的地方是:

  • HWADDR :配置mac地址
  • ONBOOT:yes
  • BOOTPROTO=“static”:
  • IPADDR:配置静态ip地址
  • GATEWAY:配置网关
  • NETMASK:配置子网掩码
  • DNS1:配置域名解析服务器修改之后

配置之后重启网卡service network restartping baidu.com 可以看到:

[root@cent01 network-scripts]# ping baidu.com
PING baidu.com (220.181.38.148) 56(84) bytes of data.
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=128 time=29.0 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=128 time=28.9 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=3 ttl=128 time=37.2 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=4 ttl=128 time=32.4 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=5 ttl=128 time=28.4 ms

表示配置成功,之后查看我们的IP地址是否配置成功:

[root@cent01 network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.52.140  netmask 255.255.255.0  broadcast 192.168.52.255
        inet6 fe80::4fbe:8c7e:a952:cfff  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:99:33:a0  txqueuelen 1000  (Ethernet)
        RX packets 85848  bytes 94883851 (90.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 24412  bytes 1479141 (1.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


注意上面的网关要和虚拟网络编辑器的网关一致才可以,下面来介绍查看网关的地址:
Centos7配置静态ip_第2张图片
这样配置好就可以了。

你可能感兴趣的:(Centos7配置静态ip)