php修改ip6地址为ip4,CentOS7 设置静态IPv6/IPv4地址

1 环境准备

实验均在Vmware Workstation虚拟机上完成,上网方式选择桥接模式,保证网络支持IPv6,为了操作方便,我们使用root用户登录系统

1.1 Linux系统版本

CentOS Linux release 7.2.1511 (Core)

1

2

[root@localhost ~]# cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

1.2 系统支持IPv6

1

2

3

4

5

6

7

8

9

10

[root@localhost ~]# ifconfig

eno16777736: flags=4163 mtu 1500

inet 49.123.105.124 netmask 255.255.192.0 broadcast 49.123.127.255

inet6 fe80::20c:29ff:fe25:c621 prefixlen 64 scopeid 0x20

inet6 2001:250:4402:2001:20c:29ff:fe25:c621 prefixlen 64 scopeid 0x0

ether 00:0c:29:25:c6:21 txqueuelen 1000 (Ethernet)

RX packets 19255 bytes 2006024 (1.9 MiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 2151 bytes 210339 (205.4 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

如图所示,可以看到系统默认的IPv6地址为2001:250:4402:2001:20c:29ff:fe25:c621

2 修改网络配置文件

根据1.2,我们得知网卡为eno16777736,切换到目录/etc/sysconfig/network-scripts下

1

[root@localhost ~]# cd /etc/sysconfig/network-scripts

编辑文件 ifcfg-eno16777736

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

[root@localhost ~]# vim ifcfg-eno16777736

TYPE=Ethernet

BOOTPROTO=none

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=no

IPV6_DEFROUTE=yes

IPV6_FAILURE_FATAL=no

NAME=eno16777736

UUID=13faf306-5205-4d3a-ac23-4699236dee95

DEVICE=eno16777736

ONBOOT=yes

DNS1=202.197.96.1

IPV6ADDR=2001:250:4402:2001:20c:29ff:fe25:8888/64

IPADDR=49.123.105.124

PREFIX=8

GATEWAY=49.123.64.1

3 重启网络

1

[root@localhost network-scripts]# systemctl restart network

4 测试是否配置成功

4.1 通过ifconfig命令查看设置的IPv6/IPv4地址

1

2

3

4

5

6

7

8

9

10

11

[root@localhost ~]# ifconfig eno16777736

eno16777736: flags=4163 mtu 1500

inet 49.123.105.124 netmask 255.0.0.0 broadcast 49.255.255.255

inet6 2001:250:4402:2001:20c:29ff:fe25:8888 prefixlen 64 scopeid 0x0

inet6 fe80::20c:29ff:fe25:c621 prefixlen 64 scopeid 0x20

inet6 2001:250:4402:2001:20c:29ff:fe25:c621 prefixlen 64 scopeid 0x0

ether 00:0c:29:25:c6:21 txqueuelen 1000 (Ethernet)

RX packets 33732 bytes 8234767 (7.8 MiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 6229 bytes 623829 (609.2 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

4.2 使用另外一台机器进行ping连接测试(两台机器均在同一局域网内)

IPv4测试

1

2

3

4

5

6

7

8

9

10

11

[root@localhost ~]# ping 49.123.105.124

PING 49.123.105.124 (49.123.105.124) 56(84) bytes of data.

64 bytes from 49.123.105.124: icmp_seq=1 ttl=64 time=0.075 ms

64 bytes from 49.123.105.124: icmp_seq=2 ttl=64 time=0.074 ms

64 bytes from 49.123.105.124: icmp_seq=3 ttl=64 time=0.092 ms

64 bytes from 49.123.105.124: icmp_seq=4 ttl=64 time=0.066 ms

64 bytes from 49.123.105.124: icmp_seq=5 ttl=64 time=0.067 ms

^C

--- 49.123.105.124 ping statistics ---

5 packets transmitted, 5 received, 0% packet loss, time 4004ms

rtt min/avg/max/mdev = 0.066/0.074/0.092/0.014 ms

IPv6测试

1

2

3

4

5

6

7

8

9

10

[root@localhost ~]# ping6 2001:250:4402:2001:20c:29ff:fe25:8888

PING 2001:250:4402:2001:20c:29ff:fe25:8888(2001:250:4402:2001:20c:29ff:fe25:8888) 56 data bytes

64 bytes from 2001:250:4402:2001:20c:29ff:fe25:8888: icmp_seq=1 ttl=64 time=0.099 ms

64 bytes from 2001:250:4402:2001:20c:29ff:fe25:8888: icmp_seq=2 ttl=64 time=0.110 ms

64 bytes from 2001:250:4402:2001:20c:29ff:fe25:8888: icmp_seq=3 ttl=64 time=0.126 ms

64 bytes from 2001:250:4402:2001:20c:29ff:fe25:8888: icmp_seq=4 ttl=64 time=0.110 ms

64 bytes from 2001:250:4402:2001:20c:29ff:fe25:8888: icmp_seq=5 ttl=64 time=0.113 ms

^C

--- 2001:250:4402:2001:20c:29ff:fe25:8888 ping statistics ---

5 packets transmitted, 5 received, 0% packet loss, time 4003ms

恭喜你,到此已经完成了CentOS 7的静态IPv6/IPV4配置

坚持原创技术分享,您的支持将鼓励我继续创作!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值