修改Linux配置的常用命令

1.修改主机名

vi /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=server1

2.修改ip地址

vi /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0TYPE=EthernetONBOOT=yes     #是否开机启用BOOTPROTO=static   #ip地址设置为静态IPADDR=192.168.0.101NETMASK=255.255.255.0service network restart

3.修改ip地址和主机名的映射关系

vi /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4::1         localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.0.101 server1
4.关闭iptables并设置其开机启动/不启动
service iptables stop
chkconfig iptables on
chkconfig iptables off
5.解决克隆后eth0不见的问题直接修改 /etc/sysconfig/network-script/ifcfg-eth0删掉UUID HWADDR 配置静态地址 然后:rm -rf  /etc/udev/rules.d/70-persistent-net.rules然后 reboot

6.修改静态地址后发现无法ping外网 
需要设置网关

route add default gw 192.168.33.1

7.添加nameserver

vi /etc/resolv.conf

nameserver 192.168.33.1

8.很多场景需要使用非root用户,所有创建一个bigdata用户:

useradd bigdata
8.1为bigdata用户添加密码:
echo 123456 | passwd --stdin bigdata

8.2将bigdata添加到sudoers

echo "bigdata ALL = (root) NOPASSWD:ALL" | tee /etc/sudoers.d/bigdata
chmod 0440 /etc/sudoers.d/bigdata

8.3解决sudo: sorry, you must have a tty to run sudo问题,在/etc/sudoer注释掉 Default requiretty 一行

sudo sed -i 's/Defaults    requiretty/Defaults:bigdata !requiretty/' /etc/sudoers

8.3创建一个bigdata目录

mkdir /{bigdata,data}

8.4给相应的目录添加权限

chown -R bigdata:bigdata /{bigdata,data}

你可能感兴趣的:(Linux)