新建一个新的Linux虚拟机需要配置的东西

配置mac地址

Ubuntu 18.04 临时修改mac

# 关闭网卡
/sbin/ifconfig eth0 down
# 更改mac地址
/sbin/ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
# 启动网卡
/sbin/ifconfig eht0 up

或者使用ip命令:

ip link set eth0 down
ip link set eth0 address xx:xx:xx:xx:xx:xx
ip ling set eth0 up

Ubuntu 18.04 永久修改mac

将修改mac地址的命令放入到 /etc/rcS.d/rc.local 文件中, rc.local 会在系统启动时执行这些命令。

或者直接修改 /etc/network/interfaces 文件,添加:

pre-up ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx

Ubuntu 20.04 修改mac

  1. 安装macchanger工具

    这一步如果有mac地址冲突会提示自动修改,那么下面的步骤就不用走了

  2. 查看所有的网络接口,找到你的网络适配器名称

  3. 查看当前网络适配器的mac地址

  4. 给网络设备随机一个mac地址

  5. 不随机,指定一个mac地址:

配置静态IP

Centos

静态ip需要修改一下选项:

systemctl restart network 重启网络即可

Ubuntu

之前版本的Ubuntu信息配置在 /etc/network/interfaces 文件中,新版本将采用netplan命令,网卡信息则会被配置在 /etc/netplan/01-network-manager-all.yaml 中:

执行 netplan apply 应用更改。

关闭selinux

查看状态

临时关闭

永久关闭

vim /etc/selinux/config

注意,需要重新启动机器才会生效。

防火墙

使用iptables关闭防火墙(centos6)

  1. 重启后生效

    开启:chkconfig iptables on

    关闭:chkconfig iptables off

  2. 即时生效,重启后失效

    开启:service iptables start

    关闭:service iptables stop

需要说明的是对于Linux下的其它服务都可以用以上命令执行开启和关闭操作。

在开启了防火墙时,做如下设置,开启相关端口,修改/etc/sysconfig/iptables 文件,添加以下内容:

使用firewalld关闭防火墙(centos7)

将firewall替换为传统的iptables

使用ufw关闭防火墙(ubuntu20.04)

配置hostname

位于 /etc/homstname 配置文件下, 默认皆为 localhost.localdomai.

查看当前主机名:

centos7修改主机名:

或者直接修改 /etc/hostname 文件.

编辑 /etc/hosts 文件,为 127.0..0.1 添加hostname:

配置root用户

如果是Ubuntu,默认的管理员账户不是root,那么需要切换到root用户再更改密码:

配置ssh

配置ssh root用户登录策略

问题描述:

当使用 SSH 登录云服务器 ECS (Elastic Compute Server) Linux 服务器时,如果是 root 用户,即便正确输入了密码,也会出现类似如下错误信息。

但非root用户可以正常登录,而且root用户通过 管理终端 登录也正常。

修改配置文件 /etc/ssh/sshd_config

image-20220111181917441
  • 未配置该参数,或者将参数值配置为 yes (默认情况),都允许 root 用户登录。只有显示的设置为 no 时,才会阻断root 用户登录。

  • 该参数只会影响用户的 SSH 登录,不影响用户通过 管理终端 等其它方式登录系统。

配置完毕后,重启ssh服务:

配置时钟同步

安装ntpd:

配置时钟服务器地址:

执行时钟同步命令:

最后更新于

这有帮助吗?