Redhat 7 &Centos 7 禁用IPV6

    在日常工作中,经常都会涉及到关闭IPV6的做法,现在记录两种关闭IPV6的方法:

目录

修改系统启动项grub,使之在引导时就不加载IPV6模块,从而关闭IPV6

1、查看系统模块中的IPV6

 2、查看IP信息

3、修改系统启动项

4、重新生成/boot/grub2/grub.cfg

5、reboot 重启操作系统

7、查看系统模块中的IPV6

8、查看IP信息

禁用IPV6

1、查看IP信息

2、修改系统的内核设置

3、应用内核设置

4、检查IP信息


  • 修改系统启动项grub,使之在引导时就不加载IPV6模块,从而关闭IPV6

1、查看系统模块中的IPV6

[root@lyp ~]# lsmod |grep ipv6
nf_conntrack_ipv6      18738  5 
nf_defrag_ipv6         34768  1 nf_conntrack_ipv6
nf_nat_ipv6            14131  1 ip6table_nat
nf_nat                 26146  3 nf_nat_ipv4,nf_nat_ipv6,nf_nat_masquerade_ipv4
nf_conntrack          105745  7 nf_nat,nf_nat_ipv4,nf_nat_ipv6,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_ipv4,nf_conntrack_ipv6

[root@lyp ~]# 

 2、查看IP信息

[root@lyp ~]# ifconfig 
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.80.127  netmask 255.255.255.0  broadcast 192.168.80.255
        inet6 fe80::20c:29ff:feb8:4673  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:46:73  txqueuelen 1000  (Ethernet)
        RX packets 105  bytes 12129 (11.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 89  bytes 15200 (14.8 KiB)
        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 0  (Local Loopback)
        RX packets 340  bytes 26628 (26.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 340  bytes 26628 (26.0 KiB)
        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:e4:e3:70  txqueuelen 0  (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@lyp ~]# 

3、修改系统启动项

[root@lyp ~]# vi /etc/default/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="ipv6.disable=1 rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
~

            在GRUB_CMDLINE_LINUX行,加上ipv6.disable=1

4、重新生成/boot/grub2/grub.cfg

[root@lyp ~]# grub2-mkconfig -o /boot/grub2/grub
grub.cfg  grubenv   
[root@lyp ~]# grub2-mkconfig -o /boot/grub2/grub.cfg 
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-a71619fe13514bc09f963b7482761417
Found initrd image: /boot/initramfs-0-rescue-a71619fe13514bc09f963b7482761417.img
done
[root@lyp ~]# 

5、reboot 重启操作系统

[root@lyp ~]# reboot
 

7、查看系统模块中的IPV6

[root@lyp ~]# lsmod |grep ipv6
[root@lyp ~]# 

8、查看IP信息

[root@lyp ~]# ifconfig 
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.80.127  netmask 255.255.255.0  broadcast 192.168.80.255
        ether 00:0c:29:b8:46:73  txqueuelen 1000  (Ethernet)
        RX packets 115  bytes 13035 (12.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 82  bytes 15428 (15.0 KiB)
        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
        loop  txqueuelen 0  (Local Loopback)
        RX packets 212  bytes 16516 (16.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 212  bytes 16516 (16.1 KiB)
        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:e4:e3:70  txqueuelen 0  (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@lyp ~]# 

  • 禁用IPV6

1、查看IP信息

[root@lyp ~]# ifconfig 
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.80.127  netmask 255.255.255.0  broadcast 192.168.80.255
        inet6 fe80::20c:29ff:feb8:4673  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:46:73  txqueuelen 1000  (Ethernet)
        RX packets 105  bytes 12129 (11.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 89  bytes 15200 (14.8 KiB)
        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 0  (Local Loopback)
        RX packets 340  bytes 26628 (26.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 340  bytes 26628 (26.0 KiB)
        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:e4:e3:70  txqueuelen 0  (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@lyp ~]# 

2、修改系统的内核设置

[root@lyp ~]# vi /etc/sysctl.conf 
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/<name>.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv6.conf.all.disable_ipv6=1
~

添加:net.ipv6.conf.all.disable_ipv6=1


3、应用内核设置

[root@lyp ~]# sysctl -p
net.ipv6.conf.all.disable_ipv6 = 1
[root@lyp ~]# 

或者reboot重启服务器

4、检查IP信息

[root@lyp ~]# ifconfig 
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.80.127  netmask 255.255.255.0  broadcast 192.168.80.255
        ether 00:0c:29:b8:46:73  txqueuelen 1000  (Ethernet)
        RX packets 223  bytes 27177 (26.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 187  bytes 33359 (32.5 KiB)
        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
        loop  txqueuelen 0  (Local Loopback)
        RX packets 276  bytes 21572 (21.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 276  bytes 21572 (21.0 KiB)
        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:e4:e3:70  txqueuelen 0  (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@lyp ~]# 

 

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值