Ubuntu网络设置

一、允许ssh登录root用户(命令行)

1、修改root 密码,sudo passwd root

2、修改ssh配置, sudo vim /etc/ssh/shd_config,修改文件中的PermitRootLogin为yes

3、重启ssh服务, sudo service ssh restart

 

 

修改主机名

 hostnamectl set-hostname  LOCALNAME

cat /etc/hostname

网卡名称

默认Ubuntu的网卡名称和centos7类似,如ens33,ens38等

修改网卡名称为传统命名方式:

#修改配置文件为下面形式

~]#vi /etc/default/grub

GRUB_CMDLINE_LINUX="net.ifnames=0"

#或者sed修改
~]# sed -i.bak '/^GRUB_CMDLINE_LINUX=/s#"$#net.ifnames=0"#'
/etc/default/grub

#生效新的grub.cfg文件
~]# grub-mkconfig -o /boot/grub/grub.cfg
#或者
~]# update-grub
~]# grep net.ifnames /boot/grub/grub.cfg

#重启生效
~]# reboot

配置自动获取IP

网卡配置文件采用YAML格式,必须以/etc/netplan/xxx.yaml文件命名方式存放可以每个网卡对应一个单独的配置文件,也可以将所有网卡都放在一个配置文件里

[root@h ~]#cat /etc/netplan/01-netcfg.yaml 
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      dhcp4: yes
      dhcp6: yes

修改网卡配置文件后需执行命令生效:

netplan apply

静态IP配置

[root@h ~]#vim /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      addresses:
      - 10.0.0.10/24
      gateway4: 10.0.0.2
      nameservers:
              addresses: [114.114.114.114, 8.8.8.8]
[root@h ~]#netplan apply 

 

posted @ 2022-04-25 15:53  goodbay说拜拜  阅读(155)  评论(0编辑  收藏  举报