1. 基本命令
hostname 查看主机名
hostname hadoop-pc 修改主机名(重启无效)
vi /etc/sysconfig/network 修改主机名( 重启后永久有效)
ifconfig eth0 192.168.12.22 修改ip地址( 重启无效)
vi /etc/sysconfig/network-scripts/ifcfg-eth0 修改IP(重启后永久生效)
date 查看日期;
du –h 或者du –ah 查看文件大小
halt 关机
reboot 重启
df -h 查看磁盘的空间
uname -a 查看系统信息
uname -r 查看系统信息
id -u 查看ID命令
id -g 查看ID命令
cat /etc/issue 查看Linux版本信息
2.配置本机IP地址
(1)配置主机名( 永久生效)
vi /etc/sysconfig/network
NETWORKING=yes HOSTNAME=sf-node2 #修改主机名 |
(2) 配置本机静态ip地址( 永久生效)
vi/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 TYPE=Ethernet ONBOOT=yes #开机是否启用 NM_CONTROLLED=yes BOOTPROTO=static #配置静态ip,dhcp动态 IPADDR=192.168.1.111 #ip地址 NETMASK=255.255.255.0 # 子网掩码 GATEWAY=192.168.1.1 # 网关 |
servicenetwork restart 重启网络服务
(3) 配置ip地址与主机名的映射
vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.1.110 sf-node1 192.168.1.111 sf-node2 192.168.1.112 sf-node3 |
3. 系统服务命令
serviceservicename status 查看指定服务状态
serviceservicename stop 停止指定服务
serviceservicename start 启动指定服务
serviceservicename restart 重启指定服务
serviceservicename --status-all 查看系统后台所有服务状态
chkconfig .查看服务的自起配置
chkconfig serveicename off 关闭指定服务的自动启动
chkconfig serveicename on 开启指定服务的自动启动
4. 设置系统的启动级别:cat /etc/inittab
# 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: |
5. 系统防火墙(iptables)
常用的命令:
service iptables start --启动防火墙
service iptables stop --关闭防火墙
service iptables restart--重新启动防火墙
service iptables save -- 保存防火墙配置
service iptablesstatus --查看防火墙的配置状态
iptables -h 或者 maniptables --查看防火墙命令的帮助
iptables -L -n -- 列出iptables规则,等同与serviceiptables status
iptables -L -n--line-numbers -- 列出iptables规则并显示规则编号
iptables -L -n -t nat -- 列出iptables nat表规则(默认是filter表)
iptables -F -- 清除默认规则(注意默认是filter表,如果对nat表操作要加-t nat)
#禁止ssh登陆(若果服务器在机房,一定要小心)
iptables -A INPUT -ptcp --dport 22 -j DROP
#删除规则
iptables -D INPUT -ptcp --dport 22 -j DROP
#添加一条规则
iptables -I INPUT -ptcp --dport 80 -j ACCEPT
选项:
-A, --append chain 追加到规则的最后一条
-D, --delete chain[rulenum] Delete rule rulenum (1 = first)from chain
-I, --insert chain[rulenum] Insert in chain as rulenum(default 1=first) 添加到规则的第一条
-p, --proto proto protocol:by number or name, eg. 'tcp',常用协议有tcp、udp、icmp、all
-j, --jump target 常见的行为有ACCEPT、DROP和REJECT三种,但一般不用REJECT,会带来安全隐患