02.centos初次使用必装配置大合集

1.安装nano
su root
yum search nano
yum install -y nano
 
2.修改主机名
查看主机名 hostname
查看主机 hostnamectl
修改主机名
su 
nano  /etc/hostname
设置主机名s101
reboot 重启
 
3.命令提示符显示当前完整路径名
su
nano  /etc/profile
添加  export PS1='[u@h `pwd`]$'
source /etc/profile  配置文件生效
exit 退出root用户
 
4.安装工具包解决ifconfig
su
yum search ifconfig
yum install -y net-tools
 
5.查看防火墙状态关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
systemctl status firewalld.service #查看firewall的状态
 
6.Linux系统centos中sudo命令不能用----提升权限
gyx is not in the sudoers file.  This incident will be reported.
1).切换到root用户 su ,如果想要切换回去 exit
2).添加sudo文件的写权限,命令是:
chmod u+w /etc/sudoers
3).编辑sudoers文件
vi /etc/sudoers
找到这行 root ALL=(ALL) ALL,在他下面添加xxx ALL=(ALL) ALL (这里的xxx是你的用户名)
centos    ALL=(ALL)    ALL
ps:这里说下你可以sudoers添加下面四行中任意一条
youuser            ALL=(ALL)                ALL
%youuser           ALL=(ALL)                ALL
youuser            ALL=(ALL)                NOPASSWD: ALL
%youuser           ALL=(ALL)                NOPASSWD: ALL
第一行:允许用户youuser执行sudo命令(需要输入密码).
第二行:允许用户组youuser里面的用户执行sudo命令(需要输入密码).
第三行:允许用户youuser执行sudo命令,并且在执行的时候不输入密码.
第四行:允许用户组youuser里面的用户执行sudo命令,并且在执行的时候不输入密码.
4).撤销sudoers文件写权限,命令:
chmod u-w /etc/sudoers
 
7.配置静态IP
1)sudo nano /etc/sysconfig/network-scripts/ifcfg-ens33
 将BOOTPROTO="dhcp" =====> BOOTPROTO="static"
 将ipv6的所有yes改成no,或者直接删除
 添加下面几行:
 IPADDR=192.168.17.100
 PREFIX=24
 GATEWAY=192.168.17.2
 DNS=192.168.17.2

 GATEWAY设置:虚拟机中点击编辑,虚拟网络编辑器,VMnat8设置 nat设置 找到网关IP
 然后重启网络 service network restart
2)修改 /etc/resolv.conf文件
    sudo nano /etc/resolv.conf
    添加(网关地址) :   nameserver 192.168.17.2
 
8.配置ip-主机映射文件 hosts
/etc/hosts
同步到s101-  s105
 
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.116.101 s101
192.168.116.102 s102
192.168.116.103 s103
192.168.116.104 s104
192.168.116.105 s105
 

原文地址:https://www.cnblogs.com/star521/p/10234613.html