Centos7 虚拟机IP配置

配置流程

1.使用dhcp方式获取ip,并查看ip地址、网关、DNS信息

2.使用静态方式配置网卡信息

3.重启网卡服务,并验证网络连接情况

具体操作如下:

第一步,使用dhcp方式获取ip,并查看ip地址、网关、DNS信息

[root@localhost aaa]# ifconfig 
ens33: flags=4163  mtu 1500
        inet 192.168.181.133  netmask 255.255.255.0  broadcast 192.168.181.255
        inet6 fe80::2186:29cf:6689:dfb7  prefixlen 64  scopeid 0x20
        ether 00:0c:29:88:a5:f2  txqueuelen 1000  (Ethernet)
        RX packets 663439  bytes 963233674 (918.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 96615  bytes 5997558 (5.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1  (Local Loopback)
        RX packets 4  bytes 240 (240.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 240 (240.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:01:29:72  txqueuelen 1000  (Ethernet)
        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

[root@localhost aaa]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.181.2   0.0.0.0         UG    100    0        0 ens33
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
192.168.181.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33
[root@localhost aaa]# 
[root@localhost aaa]# nslookup www.baidu.com
Server:		192.168.181.2
Address:	192.168.181.2#53

Non-authoritative answer:
www.baidu.com	canonical name = www.a.shifen.com.
Name:	www.a.shifen.com
Address: 61.135.169.125
Name:	www.a.shifen.com
Address: 61.135.169.121

dhcp方式获取到ip为192.168.181.133,网关和DNS都为192.168.181.2。

第二步,配置网卡信息

[root@localhost aaa]# sed -i 's/dhcp/none/' /etc/sysconfig/network-scripts/ifcfg-ens33 
[root@localhost aaa]# echo "IPADDR=192.168.181.133" >> /etc/sysconfig/network-scripts/ifcfg-ens33 
[root@localhost aaa]# echo "NETMASK=255.255.255.0" >> /etc/sysconfig/network-scripts/ifcfg-ens33 
[root@localhost aaa]# echo "GATEWAY=192.168.181.2" >> /etc/sysconfig/network-scripts/ifcfg-ens33 
[root@localhost aaa]# echo "DNS1=192.168.181.2" >> /etc/sysconfig/network-scripts/ifcfg-ens33 
[root@localhost aaa]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
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="fce08860-66e0-45ef-988c-9c7c129aa573"
DEVICE="ens33"
ONBOOT="yes"
IPADDR=192.168.181.133
NETMASK=255.255.255.0
GATEWAY=192.168.181.2
DNS1=192.168.181.2

第三步,重启网卡服务,并验证网络连接情况

[root@localhost aaa]# systemctl restart network
[root@localhost aaa]# ifconfig 
ens33: flags=4163  mtu 1500
        inet 192.168.181.133  netmask 255.255.255.0  broadcast 192.168.181.255
        inet6 fe80::2186:29cf:6689:dfb7  prefixlen 64  scopeid 0x20
        ether 00:0c:29:88:a5:f2  txqueuelen 1000  (Ethernet)
        RX packets 663505  bytes 963238329 (918.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 96667  bytes 6003559 (5.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1  (Local Loopback)
        RX packets 4  bytes 240 (240.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 240 (240.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:01:29:72  txqueuelen 1000  (Ethernet)
        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

[root@localhost aaa]# ping -c1 www.baidu.com
PING www.a.shifen.com (61.135.169.125) 56(84) bytes of data.
64 bytes from 61.135.169.125 (61.135.169.125): icmp_seq=1 ttl=128 time=3.67 ms

--- www.a.shifen.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 3.679/3.679/3.679/0.000 ms
[root@localhost aaa]#

验证通过,达到预期效果(ip可以选择其它,只要和网关一个网段就行)~!~

你可能感兴趣的:(Zabbix学习,Linux/Shell,linux,运维)