IPv6被認爲是IPv4的替代產品,它用來解決現有IPv4地址空間即將耗盡的問題。
但目前,開啓IPv6可能會致使一些問題。所以有時咱們須要關閉IPv6。
下面是IPv6的關閉方法應該適用於全部主流的Linux發行版包括Ubuntu、Debian、CentOS。mysql
IPv6在CentOS6.5系統中默認是啓用狀態,經過如下方式能夠確認IPv6的狀態linux
如下命令返回值爲0表示IPv6啓用,1表示禁用redis
cat /proc/sys/net/ipv6/conf/all/disable_ipv6 cat /proc/sys/net/ipv6/conf/default/disable_ipv6
ifconfig ip address list netstat -anptl
# 有返回結果,說明IPv6模塊已啓用,能夠看出那些程序進行了調用,反之沒有啓用sql
lsmod | grep ipv6
# 命令行調整內核參數,臨時禁用IPv6vim
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
echo " ">>/etc/sysctl.conf echo "# made for disabled IPv6 in $(date +%F)">>/etc/sysctl.conf echo 'net.ipv6.conf.all.disable_ipv6 = 1'>>/etc/sysctl.conf echo 'net.ipv6.conf.default.disable_ipv6 = 1'>>/etc/sysctl.conf echo 'net.ipv6.conf.lo.disable_ipv6 = 1'>>/etc/sysctl.conf tail -5 /etc/sysctl.conf sysctl -p netstat -anptl
也能夠直接編輯系統內核配置文件ssh
vim /etc/sysctl.conf ------------------------------------------------------ # Made for disabled IPv6 . net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1 -------------------------------------------------------
# 若是想要爲特定的網卡禁止IPv6,好比eth1,改成添加下面的行。memcached
net.ipv6.conf.eth1.disable_ipv6 = 1
# 注意檢查修改network配置文件中的IPv6配置post
vim /etc/sysconfig/network -------------------------------------- NETWORKING_IPV6=no --------------------------------------
# 注意修改ifcfg-eth0spa
vim /etc/sysconfig/network-scripts/ifcfg-eth0 ---------------------------------- IPV6INIT=no ----------------------------------
1)修改ssh配置,只監聽IPv4地址命令行
vim /etc/ssh/sshd_config ---------------------------------------- # 在第15行的前面去掉註釋(#): ListenAddress 0.0.0.0 AddressFamily inet ---------------------------------------- service sshd restart netstat -anptl
# 注意:inet爲僅IPv4,inet6爲僅IPv6,any爲都支持
2)mysql配置問題
mysql安裝後默認會監聽IPv6地址,關閉IPv6後,須要編輯,在[mysqld]中添加
vim /etc/my.cnf ---------------------------------------- bind-address=0.0.0.0 ----------------------------------------
修改完重啓mysql便可
3)配置redis,監聽IPv4地址
vim /usr/local/redis/conf/redis.conf ---------------------------------------- bind 127.0.0.1 ----------------------------------------
4)配置memcached,監聽IPv4地址
# 配置memcached,監聽地址須要使用IP,使用localhost沒法啓動memcached
# memcached /usr/local/memcached/bin/memcached -u root -p 12001 -l 127.0.0.1 -d -P /tmp/memcached1.pid
5)配置VSFTP
vim /etc/vsftpd/vsftpd.conf ---------------------------------------- listen=YES listen_ipv6=NO ----------------------------------------
6)配置postfix監聽IPv4地址
vim /etc/postfix/main.cf ---------------------------------------- inet_interfaces = 127.0.0.1 ----------------------------------------
7)配置dovecot監聽IPv4地址
vim /etc/dovecot/dovecot.conf ---------------- listen * ----------------
8)配置xinetd
# xinetd.conf第32行修改成: vim /etc/xinetd.conf ------------------------ bind = 0.0.0.0 ------------------------ # 從新載入配置文件 service xinetd reload
以上是禁用IPv6以後可能會受到影響的程序,能夠根據本身的實際狀況進行配置
cat /proc/sys/net/ipv6/conf/all/disable_ipv6 cat /proc/sys/net/ipv6/conf/default/disable_ipv6
echo 0 >/proc/sys/net/ipv6/conf/all/disable_ipv6 echo 0 >/proc/sys/net/ipv6/conf/default/disable_ipv6 # 或着 sysctl -w net.ipv6.conf.all.disable_ipv6=0 sysctl -w net.ipv6.conf.default.disable_ipv6=0
修改完是臨時的,重啓失效
vim /etc/sysctl.conf ---------------------------------------------- net.ipv6.conf.all.disable_ipv6 = 0 net.ipv6.conf.default.disable_ipv6 = 0 net.ipv6.conf.lo.disable_ipv6 = 0 ---------------------------------------------- sysctl -p
modprobe ipv6
[root@zstest ~]# modprobe ipv6 FATAL: Module off not found.
失敗緣由:未啓用IPv6模塊
解決方法:
須要編輯配置文件,啓用IPv6內核模塊,在禁用狀態下沒法調用ipv6模塊
該處理須要重啓系統,啓動後ipv6模塊自動調用
vim /etc/modprobe.d/disable_ipv6.conf -------------------------------- #alias net-pf-10 off #alias ipv6 off options ipv6 disable=0 --------------------------------- [root@zstest ~]# lsmod |grep ipv6 ipv6 335781 14
完畢,呵呵呵呵