ubuntu系统 连接服务器配置,ubuntu 服务器基础配置

设置静态ip

vim /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)

auto lo

iface lo inet loopback

# The primary network interface

auto ens33

#iface eth0 inet dhcp

iface ens33 inet static

address 192.168.66.222

netmask 255.255.255.0

gateway 192.168.66.254

# interfaces(5) file used by ifup(8) and ifdown(8)

autolo

ifaceloinetloopback

# The primary network interface

autoens33

#iface eth0 inet dhcp

ifaceens33inetstatic

address192.168.66.222

netmask255.255.255.0

gateway192.168.66.254

注意上面的网卡名称 要换成你自己机器的名称

设置DNS

# vim /etc/resolv.conf

添加如下内容(这点所有Linux发行版都通用):

nameserver 192.168.66.254

nameserver 8.8.8.8

保存退出。

注意:重启Ubuntu后发现又不能上网了,问题出在/etc/resolv.conf。重启后,此文件配置的dns又被自动修改为默认值。所以需要永久性修改DNS。方法如下:

# vim /etc/resolvconf/resolv.conf.d/base

nameserver 192.168.66.254

nameserver 8.8.8.8

要想修改resolv.conf重启后不被修改,那么进行如下操作。

1.关闭systemd-resolvd服务

systemctl stop systemd-resolvd

systemctl disable systemd-resolvd

这样对/etc/resolv.conf做出的修改都能保存下来。

2.unbound自动配置

sudo systemctl stop systemd-resolved

sudo systemctl disable systemd-resolved

sudo apt install unbound

sudo rm -rf /etc/resolv.conf

sudo vim /etc/NetworkManager/NetworkManager.conf

重启电脑即可,开机查看resolve.conf发现nameserver自动配置

参考链接:https://blog.csdn.net/midae/article/details/92403306

# vim /etc/resolv.conf

添加如下内容(这点所有Linux发行版都通用):

nameserver192.168.66.254

nameserver8.8.8.8

保存退出。

注意:重启Ubuntu后发现又不能上网了,问题出在/etc/resolv.conf。重启后,此文件配置的dns又被自动修改为默认值。所以需要永久性修改DNS。方法如下:

# vim /etc/resolvconf/resolv.conf.d/base

nameserver192.168.66.254

nameserver8.8.8.8

要想修改resolv.conf重启后不被修改,那么进行如下操作。

1.关闭systemd-resolvd服务

systemctlstopsystemd-resolvd

systemctldisablesystemd-resolvd

这样对/etc/resolv.conf做出的修改都能保存下来。

2.unbound自动配置

sudosystemctlstopsystemd-resolved

sudosystemctldisablesystemd-resolved

sudoaptinstallunbound

sudorm-rf/etc/resolv.conf

sudovim/etc/NetworkManager/NetworkManager.conf

重启电脑即可,开机查看resolve.conf发现nameserver自动配置

参考链接:https://blog.csdn.net/midae/article/details/92403306

3、重启networking服务使其生效

# /etc/init.d/networking restart

# /etc/init.d/networking restart

关闭图形界面,使用图形界面登录

。sudo systemctl set-default multi-user.target

sudo reboot

开启用户图形界面。sudo systemctl set-default graphical.target

sudo reboot

。sudosystemctlset-defaultmulti-user.target

sudoreboot

开启用户图形界面。sudosystemctlset-defaultgraphical.target

sudoreboot

关闭防火墙

ufw status

ufwstatus

设置允许ssh连接

启ssh服务首先需要安装打开ssh服务的库:

sudo apt-get install openssh-server

检查当前的ssh开启情况:

ps -e |grep ssh

如果有sshd,则ssh-server已经启动;若仅有agent,则尚未启动;

开启ssh服务:

/etc/init.d/ssh start

若为启动或者希望重启ssh,则修改配置并重启ssh服务:

vi /etc/ssh/sshd_config

则可以看到配置文件,按照需求修改即可;

重启ssh:

sudo /etc/init.d/ssh restart

ubuntu 设置允许ssh远程连接

1. 支持ssh root连接,在文献中提到的 sudo vim /etc/ssh/sshd_config

底部插入

PermitRootLogin yes

ssh重启

sudo service ssh restart

启ssh服务首先需要安装打开ssh服务的库:

sudoapt-getinstallopenssh-server

检查当前的ssh开启情况:

ps-e|grepssh

如果有sshd,则ssh-server已经启动;若仅有agent,则尚未启动;

开启ssh服务:

/etc/init.d/sshstart

若为启动或者希望重启ssh,则修改配置并重启ssh服务:

vi/etc/ssh/sshd_config

则可以看到配置文件,按照需求修改即可;

重启ssh:

sudo/etc/init.d/sshrestart

ubuntu设置允许ssh远程连接

1.支持sshroot连接,在文献中提到的sudovim/etc/ssh/sshd_config

底部插入

PermitRootLoginyes

ssh重启

sudoservicesshrestart

ubuntu 18.4 使用 Netplan 配置网络教程

1、查看配置文件

ls /etc/netplan/

ls/etc/netplan/

2、打开配置文件

vim /etc/netplan/*.yaml

vim/etc/netplan/*.yaml

3、修改配置文件

3.1 使用 DHCP分配ip:

network:

version: 2

renderer: networkd

ethernets:

enp3s0:

dhcp4: true

network:

version:2

renderer:networkd

ethernets:

enp3s0:

dhcp4:true

3.2 配置静态ip

network:

version: 2

renderer: networkd

ethernets:

eno1:

addresses:

– 192.168.188.239/24

gateway4: 255.255.255.0

nameservers:

addresses: [192.168.188.1,114.114.114.114]

network:

version:2

renderer:networkd

ethernets:

eno1:

addresses:

-192.168.188.239/24

gateway4:255.255.255.0

nameservers:

addresses:[192.168.188.1,114.114.114.114]

network:

version: 2

renderer: networkd

ethernets:

eno1:

addresses: [192.168.188.239/24]

gateway4: 255.255.255.0

nameservers:

addresses: [192.168.188.1,114.114.114.114]

network:

version:2

renderer:networkd

ethernets:

eno1:

addresses:[192.168.188.239/24]

gateway4:255.255.255.0

nameservers:

addresses:[192.168.188.1,114.114.114.114]

3.3 多个网口 DHCP:

network:

version: 2

ethernets:

enred:

dhcp4: yes

dhcp4-overrides:

route-metric: 100

engreen:

dhcp4: yes

dhcp4-overrides:

route-metric: 200

network:

version:2

ethernets:

enred:

dhcp4:yes

dhcp4-overrides:

route-metric:100

engreen:

dhcp4:yes

dhcp4-overrides:

route-metric:200

3.4连接开放的 WiFi(无密码):

network:

version: 2

wifis:

wl0:

access-points:

opennetwork: {}

dhcp4: yes

network:

version:2

wifis:

wl0:

access-points:

opennetwork:{}

dhcp4:yes

3.5 连接 WPA 加密的 WiFi:

network:

version: 2

renderer: networkd

wifis:

wlp2s0b1:

dhcp4: no

dhcp6: no

addresses: [192.168.0.21/24]

gateway4: 192.168.0.1

nameservers:

addresses: [192.168.0.1, 8.8.8.8]

access-points:

"network_ssid_name":

password: "**********"

network:

version:2

renderer:networkd

wifis:

wlp2s0b1:

dhcp4:no

dhcp6:no

addresses:[192.168.0.21/24]

gateway4:192.168.0.1

nameservers:

addresses:[192.168.0.1,8.8.8.8]

access-points:

"network_ssid_name":

password:"**********"

3.6 在单网卡上使用多个 IP 地址(同一网段):

network:

version: 2

renderer: networkd

ethernets:

enp3s0:

addresses:

– 10.100.1.38/24

– 10.100.1.39/24

gateway4: 10.100.1.1

network:

version:2

renderer:networkd

ethernets:

enp3s0:

addresses:

-10.100.1.38/24

-10.100.1.39/24

gateway4:10.100.1.1

3.7 在单网卡使用多个不同网段的 IP 地址:

network:

version: 2

renderer: networkd

ethernets:

enp3s0:

addresses:

– 9.0.0.9/24

– 10.0.0.10/24

– 11.0.0.11/24

#gateway4: # unset, since we configure routes below

routes:

– to: 0.0.0.0/0

原文链接:https://blog.csdn.net/weixin_36462387/article/details/119511325

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享