※修改主机名:
- centos5/6
- 1,/etc/sysconfig/network
2, 修改 hosts 文件:/etc/hosts
centos7
1,/etc/hostname, 或者 hostnamectl set-hostname newhostname
2, 修改 host 文件
※将网卡改为默认开机自动启动:
※同步服务器时间
CentOS 5/6
1, 在 / etc/ntp.conf 里面加: server 170.18.0.1 iburst
2,service ntpd status &>/dev/null || service ntpd start &>/dev/null
3, 设置开机启动: chkconfig ntpd on
4, 同步时间: ntpdate 172.18.0.1
CentOS 7
1./etc/chrony.conf 里面加 server 172.18.0.1 iburst
2.systemctl status chronyd &>/dev/null || systemctl start chronyd &>/dev/null
3. 设置开机启动: systemctl enable chronyd &>/dev/null
4. 同步时间: ntpdate 172.18.0.1
※查看文件或者目录大小: du -sh 目录名 / 文件名
※新加硬盘 df 不显示, 需要激活:
- echo '- - -'> /sys/class/scsi_host/host2/scan
- echo '- - -'> /sys/class/scsi_host/host0/scan
- echo '- - -'> /sys/class/scsi_host/host1/scan
※取 passwd 中用户名和 bash 一样的行: getent passwd|egrep "^([a-z]+):.*/\1$"
※echo CentOS| passwd --stdin luo>/dev/null
※Centos7 配置网卡名为 eth0
/etc/sysconfig/network-scripts/ifcfg-ens33(或则 eth0)
ONBOOT 改为 yes
1, 在 / etc/default/grub 里面 GRUB_CMDLINE 后面加 net.ifnames=0
或 / boot/grub2/grub.cfg 中第一个 Linux 16 开头行尾 net.ifnames=0
如果是 dell 服务器 (rpm -qi biosdevname) 需另外加 biosdevname=0
2, 执行命令: grub2-mkconfig -o /boot/grub2/grub.cfg
如果是 efi 的需要执行 grub2-mkconfig -o /boot/grub2/efi grub.cfg
3, 重启生效
※Ubuntu 配置网络
一, 网卡名配置为 eth0
1, 在 / etc/default/grub 里面 GRUB_CMDLINE 后面加 net.ifnames=0
2, 执行命令: grub-mkconfig -o /boot/grub/grub.cfg
3, 重启生效
二, 配置动态 ip
配置静态 IP
※防火墙
iptables -vnL 查看防火墙
iptables -F 关闭防火墙
CentOS 6
关闭防火墙: service iptables stop
关闭防火墙下次开机不启动: chkconfig iptables off
CentOS 7
systemctl stop firewalld 关闭防火墙
systemctl disable firewalld 下次开机不启动防火墙
把某个 IP 加进防火墙: iptables -A INPUT -s 192.168.33.107 -j REJECT
※centos7 设置光盘自动挂载:
- yum install autofs
- systemctl start autofs
- systemctl enable autofs
※关闭 SElinux 的步骤:/etc/selinux/config 中 SELINUX=disabled
批量关闭主机列表中的 selinux:
pssh -h /data/hostip.txt "sed -i.bak -r's/^(SELINUX=).*/\1disabled/'/etc/selinux/config"
※关闭 SSH 反向解析:
- ###CentOS 6 设置 #####
- sed -r -i.bak -e "[email protected]^#(UseDNS)@\[email protected]" -e "[email protected]^#(GSSAPIAuthentication)@\[email protected]" /etc/SSH/sshd_config
关闭 SSH 反向解析, 79 行 GSSAPIAuthentication yes 改为 no, 去掉 #号, 115 行 #UserDNS no 前的 #号去掉
重启服务 service sshd restart
centos7 设置 ##########
sed -r -i.bak -e '[email protected]^(GSSAPIAuthentication )[email protected]\[email protected]' -e '[email protected]^#(UseDNS )[email protected]\[email protected]' /etc/SSH/sshd_config
重启服务 systemctl restart sshd
※系统开机默认启动模式:
centos6:cat /etc/inttab, 改为 3
centos7:systemctl set-default multi-user.target
来源: http://www.bubuko.com/infodetail-3163335.html