合 CentOS 7禁用IPV6
IPV6简介
IPv6早在上个世纪90年代,它就已经诞生了。IPv6全称Internet Protocol version 6,是网际协议的最新版本,用作互联网的协议。用它来取代IPv4主要是为了解决IPv4地址枯竭问题,同时它也在其他方面对于IPv4有许多改进。
是否应该“启用或者关闭”IPV6协议并不是一个很容易回答的问题。这就象是一片灰色地带,充满了各种各样的观点。
CentOS 7.* 在启动时默认加载IPv6相关模块,docker默认使用tcp6。
IPv6在未来可能成为主流,但是就目前而言,很多软件对IPv6的支持并不是很完善,可能导致各类问题。RHEL 7 & CentOS 7 在启动时默认是加载IPv6相关模块的,所以,可以选择禁用IPV6。
查询
如下,有tcp6和udp6,说明启用了IPV6。
通过ifconfig,能看到inet6说明开启了IPV6
1 2 3 | ifconfig | grep inet6 netstat -tulnp | grep p6 lsmod | grep ipv6 |
示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | [root@eas-ora ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.40.1.11 netmask 255.255.255.0 broadcast 10.40.1.255 inet6 fe80::f816:3eff:fedc:ddce prefixlen 64 scopeid 0x20<link> ether fa:16:3e:dc:dd:ce txqueuelen 1000 (Ethernet) RX packets 11990236912 bytes 7276032353783 (6.6 TiB) RX errors 0 dropped 0 overruns 0 frame 6129 TX packets 9018624475 bytes 11215132534244 (10.2 TiB) 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 32803862 bytes 2875819543 (2.6 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 32803862 bytes 2875819543 (2.6 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:21:e1:22 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@lhr ~]# netstat -tulnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 162/sshd tcp 0 0 0.0.0.0:1401 0.0.0.0:* LISTEN 6518/docker-proxy tcp 0 0 0.0.0.0:1402 0.0.0.0:* LISTEN 6118/docker-proxy tcp 0 0 0.0.0.0:1433 0.0.0.0:* LISTEN 5694/docker-proxy tcp6 0 0 :::22 :::* LISTEN 162/sshd tcp6 0 0 :::1401 :::* LISTEN 6525/docker-proxy tcp6 0 0 :::1402 :::* LISTEN 6126/docker-proxy tcp6 0 0 :::1433 :::* LISTEN 5700/docker-proxy tcp6 0 0 :::3389 :::* LISTEN 173/xrdp tcp6 0 0 ::1:3350 :::* LISTEN 170/xrdp-sesman udp 0 0 0.0.0.0:1968 0.0.0.0:* 190/edge udp 0 0 127.0.0.1:5644 0.0.0.0:* 190/edge udp 0 0 172.17.0.1:123 0.0.0.0:* 82/ntpd udp 0 0 172.72.0.1:123 0.0.0.0:* 82/ntpd udp 0 0 192.168.88.100:123 0.0.0.0:* 82/ntpd udp 0 0 192.168.8.8:123 0.0.0.0:* 82/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 82/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 82/ntpd udp 0 0 0.0.0.0:49388 0.0.0.0:* 190/edge udp 0 0 127.0.0.1:323 0.0.0.0:* - udp6 0 0 fe80::a882:3bff:fea:123 :::* 82/ntpd udp6 0 0 fe80::5429:79ff:feb:123 :::* 82/ntpd udp6 0 0 fe80::c0e0:b0ff:fed:123 :::* 82/ntpd udp6 0 0 fe80::42:e3ff:fe3d::123 :::* 82/ntpd udp6 0 0 fe80::884b:e5ff:fe1:123 :::* 82/ntpd udp6 0 0 fe80::215:5dff:fe4e:123 :::* 82/ntpd udp6 0 0 ::1:123 :::* 82/ntpd udp6 0 0 :::123 :::* 82/ntpd udp6 0 0 ::1:323 :::* - [root@lhr ~]# [root@lhr ~]# netstat -tulnp | grep p6 tcp6 0 0 :::22 :::* LISTEN 162/sshd tcp6 0 0 :::1401 :::* LISTEN 6525/docker-proxy tcp6 0 0 :::1402 :::* LISTEN 6126/docker-proxy tcp6 0 0 :::1433 :::* LISTEN 5700/docker-proxy tcp6 0 0 :::3389 :::* LISTEN 173/xrdp tcp6 0 0 ::1:3350 :::* LISTEN 170/xrdp-sesman udp6 0 0 fe80::a882:3bff:fea:123 :::* 82/ntpd udp6 0 0 fe80::5429:79ff:feb:123 :::* 82/ntpd udp6 0 0 fe80::c0e0:b0ff:fed:123 :::* 82/ntpd udp6 0 0 fe80::42:e3ff:fe3d::123 :::* 82/ntpd udp6 0 0 fe80::884b:e5ff:fe1:123 :::* 82/ntpd udp6 0 0 fe80::215:5dff:fe4e:123 :::* 82/ntpd udp6 0 0 ::1:123 :::* 82/ntpd udp6 0 0 :::123 :::* 82/ntpd udp6 0 0 ::1:323 :::* - [root@lhr ~]# [root@eas-ora ~]# ifconfig | grep inet6 inet6 fe80::f816:3eff:fedc:ddce prefixlen 64 scopeid 0x20<link> inet6 ::1 prefixlen 128 scopeid 0x10<host> |
禁用IPV6
方法 1
1、编辑文件vi /etc/sysctl.conf
,添加如下的内容:
1 2 | net.ipv6.conf.all.disable_ipv6 =1 net.ipv6.conf.default.disable_ipv6 =1 |
或者:
1 2 3 4 5 | echo 1> /proc/sys/net/ipv6/conf/all/disable_ipv6 echo 1> /proc/sys/net/ipv6/conf/default/disable_ipv6 sysctl -w net.ipv6.conf.all.disable_ipv6=1 sysctl -w net.ipv6.conf.default.disable_ipv6=1 |
2、如果你想要为特定的网卡禁止IPv6,比如,对于eth0,则需要添加下面的行:
1 | net.ipv6.conf.eth0.disable_ipv6 =1 |
3、修改网络配置文件
1 2 | vi /etc/sysconfig/network NETWORKING_IPV6=no |
4、修改网卡配置文件
1 2 | vi /etc/sysconfig/network-scripts/ifcfg-XX IPV6INIT=no |
5、禁用ip6tables服务
1 2 3 | systemctl status ip6tables systemctl stop ip6tables systemctl disable ip6tables |
6、执行下面的命令来使设置生效。