- 1、CentOS 6.3未关闭ipv6前:
- [root@localhost ~]# ifconfig
- eth0 Link encap:Ethernet HWaddr 14:FE:B5:E4:88:37
- inet addr:192.168.7.5 Bcast:192.168.7.255 Mask:255.255.255.0
- inet6 addr: fe80::16fe:b5ff:fee4:8837/64 Scope:Link
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
- RX packets:29241896 errors:0 dropped:0 overruns:0 frame:0
- TX packets:6367343 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:2183886705 (2.0 GiB) TX bytes:1303582168 (1.2 GiB)
- Interrupt:16
- lo Link encap:Local Loopback
- inet addr:127.0.0.1 Mask:255.0.0.0
- inet6 addr: ::1/128 Scope:Host
- UP LOOPBACK RUNNING MTU:16436 Metric:1
- RX packets:188 errors:0 dropped:0 overruns:0 frame:0
- TX packets:188 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:14792 (14.4 KiB) TX bytes:14792 (14.4 KiB)
- 2、通过内核模块加载信息查看
- [root@localhost ~]# lsmod |grep ipv6
- ipv6 322029 43 cnic
- 注释:有 “inet6 addr:。。。。。。。“ 的表示开启了ipv6功能。
- 3、ipv6关闭方法
- 在/etc/modprobe.d/dist.conf结尾添加
- alias net-pf-10 off
- alias ipv6 off
- 可用vi等编辑器,也可以通过命令:
- [root@localhost ~]# cat <<EOF>>/etc/modprobe.d/dist.conf
- alias net-pf-10 off
- alias ipv6 off
- EOF
- 4、关闭ip6的iptables
- [root@localhost ~]# chkconfig ip6tables off
- [root@localhost ~]# reboot
- 5、重启后:
- [root@localhost ~]# lsmod |grep ipv6
- [root@localhost ~]# ifconfig
- eth0 Link encap:Ethernet HWaddr BC:30:5B:C0:CD:4F
- inet addr:192.168.7.5 Bcast:192.168.7.255 Mask:255.255.255.0
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
- RX packets:803 errors:0 dropped:0 overruns:0 frame:0
- TX packets:78 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:55708 (54.4 KiB) TX bytes:9946 (9.7 KiB)
- Interrupt:16
- lo Link encap:Local Loopback
- inet addr:127.0.0.1 Mask:255.0.0.0
- UP LOOPBACK RUNNING MTU:16436 Metric:1
- RX packets:0 errors:0 dropped:0 overruns:0 frame:0
- TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
- CentOS 5
- 1:编辑/etc/sysconfig/network
- 默认是yes,改成no
- NETWORKING_IPV6=no
- 2:编辑 /etc/modprobe.conf
- 如果没有就添加下面两行
- alias net-pf-10 off
- alias ipv6 off
- 3:停止服务
- #chkconfig ip6tables off
- 4:重启
- centos6.3 禁用IPv6
- IPv6还没有完全普及,但是安装完系统之后IPv6是有效的,在一定程度上影响网络性能,所以在我们在完全不使用IPv6的情况下,最好关闭IPv6。其实在上一篇网络设置的文章中,我们提到过是否激活IPv6,但是只是那一点设置还是不能完全关闭IPv6,所以本文以完整的步骤叙述一下如何关闭它。
- 1.修改/etc/sysconfig/network,追加:
- NETWORKING_IPV6=no
- 2.修改/etc/hosts,把ipv6的那句本地主机名解析的也注释掉:
- #::1 localhost localhost6 localhost6.localdomain6
- 3.让系统不加载ipv6相关模块,这需要修改modprobe相关设定文件,为了管理方便,我们新建设定文件/etc/modprobe.d/ipv6off.conf,内容如下,三种方式,总有一款适合你:
- 推荐:
- alias net-pf-10 off
- options ipv6 disable=1
- 或者 install ipv6 /bin/true
- 或者 install ipv6 /sbin/modprobe -n -i ipv6
- 注意,如果你使用了网卡绑定(bond)技术,而且不希望用ipv6,那么你使用第一种,否则系统启动时,bonding模块可能会加载失败。
- 4.重启系统,然后确认:
- [root@test ~]# lsmod | grep -i ipv6
- [root@test ~]# ifconfig | grep -i inet6
- 如果上述2个命令执行的结果没有任何显示,那么说明ipv6已经被完全禁止了。
- 后记:
- 在第三步不加载ipv6模块的方法里,可能有人会有类似这样的设置方法:
- alias net-pf-10 off
- alias ipv6 off
- options ipv6 disable=1
- 虽然这样在系统重启后,ipv6的确没被加载,但是因为第二句,在有的版本的系统里,当我们重启网络的时候,会出现如下错误:
FATAL: Module off not found.
我估计大家都不希望在启动过程中看到FATAL这样的错误信息,所以我就采用正文里所设置的方法。
关闭多余tty前:
- [root@CentOS ~]# ps aux |grep tty
- root 1359 0.0 0.0 4056 592 tty1 Ss+ 17:42 0:00 /sbin/mingetty /dev/tty1
- root 1361 0.0 0.0 4056 592 tty2 Ss+ 17:42 0:00 /sbin/mingetty /dev/tty2
- root 1363 0.0 0.0 4056 596 tty3 Ss+ 17:42 0:00 /sbin/mingetty /dev/tty3
- root 1365 0.0 0.0 4056 592 tty4 Ss+ 17:42 0:00 /sbin/mingetty /dev/tty4
- root 1367 0.0 0.0 4056 596 tty5 Ss+ 17:42 0:00 /sbin/mingetty /dev/tty5
- root 1369 0.0 0.0 4056 596 tty6 Ss+ 17:42 0:00 /sbin/mingetty /dev/tty6
- root 1398 0.0 0.0 103232 868 pts/0 S+ 17:44 0:00 grep tty
CentOS5之前是直接在/etc/inittab文件中注释多余tty就可以了,但是6.3发生了改变。/etc/inittab中没有/etc/inittab选项。
- [root@CentOS ~]# vi /etc/sysconfig/init
- # color => new RH6.0 bootup
- # verbose => old-style bootup
- # anything else => new style bootup without ANSI colors or positioning
- BOOTUP=color
- # column to start "[ OK ]" label in
- RES_COL=60
- # terminal sequence to move to that column. You could change this
- # to something like "tput hpa ${RES_COL}" if your terminal supports it
- MOVE_TO_COL="echo -en \\033[${RES_COL}G"
- # terminal sequence to set color to a 'success' color (currently: green)
- SETCOLOR_SUCCESS="echo -en \\033[0;32m"
- # terminal sequence to set color to a 'failure' color (currently: red)
- SETCOLOR_FAILURE="echo -en \\033[0;31m"
- # terminal sequence to set color to a 'warning' color (currently: yellow)
- SETCOLOR_WARNING="echo -en \\033[0;33m"
- # terminal sequence to reset to the default color.
- SETCOLOR_NORMAL="echo -en \\033[0;39m"
- # Set to anything other than 'no' to allow hotkey interactive startup...
- PROMPT=yes
- # Set to 'yes' to allow probing for devices with swap signatures
- AUTOSWAP=no
- # What ttys should gettys be started on?
- #ACTIVE_CONSOLES=/dev/tty[1-6]
- ACTIVE_CONSOLES=/dev/tty[1-3] ###改这里哦!!
- # Set to '/sbin/sulogin' to prompt for password on single-user mode
- # Set to '/sbin/sushell' otherwise
- SINGLE=/sbin/sushell
- [root@CentOS ~]# reboot
- [root@CentOS ~]# ps aux |grep tty
- root 1360 0.0 0.0 4056 596 tty1 Ss+ 17:46 0:00 /sbin/mingetty /dev/tty1
- root 1362 0.0 0.0 4056 596 tty2 Ss+ 17:46 0:00 /sbin/mingetty /dev/tty2
- root 1364 0.0 0.0 4056 596 tty3 Ss+ 17:46 0:00 /sbin/mingetty /dev/tty3
- root 1385 0.0 0.0 103232 868 pts/0 S+ 17:46 0:00 grep tty