一、开机关机
1、Linux centos重启命令:
- reboot
- shutdown -r now 立刻重启(root用户使用)
- shutdown -r 10 过10分钟自动重启(root用户使用)
- shutdown -r 20:35 在时间为20:35时候重启(root用户使用)
- 如果是通过shutdown命令设置重启的话,可以用shutdown -c命令取消重启
2、Linux centos关机命令:
- halt 立刻关机
- poweroff 立刻关机
- shutdown -h now 立刻关机(root用户使用)
- shutdown -h 10 10分钟后自动关机
如果是通过shutdown命令设置关机的话,可以用shutdown -c命令取消重启
二、图形界面与命令界面的切换
临时由命令界面转成图形界面 : [root@localhost ~]startx
1、修改/etc/inittab文件,文件中,最后一行id:5:initdefault: 中的5改成3,重启即可
重启命令: shutdown -r now
[root@localhost ~]# vim /etc/inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault:
2、对修改的配置详解
其中 5 和 3 的意思为:
0:关机
1:单用户模式,不需要root密码直接用root登陆,忘记密码时可以用来直接修改管理员密码。
2:多用户模式但是不启用网络
3:多用户命令行模式
4:未启用
5:centos图形化界面模式,gnome或者kde等等
6:重启
三、配置网段
1、命令方式
使用桥接的方式
[root@localhost network-scripts]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="none" // 不使用dhcp
HWADDR="00:0C:29:DE:25:25"
IPV6INIT="no" //
NM_CONTROLLED="yes"
ONBOOT="yes"
PEERDNS="yes"
UUID="5ad5cd19-744e-45b9-924e-d4d681e7bcbc"
TYPE="Ethernet" //类型是以太网
NETMASK="255.255.0.0" // 子网掩码
IPADDR="172.29.27.199" // ip地址
GATEWAY="172.29.27.1" //网关
~
重启网卡
/etc/init.d/network restart
2、图形界面方式
a,右键点击右上角的电脑图标,选择edit Connections
b,然后编辑网卡
c,然后,选择ipv4,填写地址,子网掩码,网关。即可
d,然后左键点击右上角电脑图标,重启网卡
四、开放端口
命令: vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允许80端口通过防火墙)
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT(允许3306端口通过防火墙)
特别提示:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,正确的应该是添加到默认的22端口这条规则的下面
添加好之后防火墙规则如下所示:
Firewall configuration written by system-config-firewall
Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
/etc/init.d/iptables restart
#最后重启防火墙使配置生效
五、关闭防火墙
-
重启后生效
开启: chkconfig iptables on
关闭: chkconfig iptables off -
即时生效,重启后失效
开启: service iptables start
关闭: service iptables stop