ubuntu服务器配置网络(ubuntu 服务器 联网)

Ubuntu 网卡配置命令

使用 命令行 在Ubuntu Linux中重新启动网络

如果你使用的是Ubuntu服务器版,则已经在终端中。如果使用的是桌面版,则可以使用Ubuntu中的Ctrl+Alt+T键盘快捷方式访问终端。

现在,可以使用多个命令在Ubuntu中重新启动网络,要说明的是,命令也适用于在Debian和其他Linux发行版中重新启动网络。

这是使用命令行重新启动网络的最简单方法,它等同于图形化方式(重新启动Network-Manager服务)。

sudo service network-manager restart

网络图标应该消失片刻,然后重新出现。

service命令只是此方法的包装器(也适用于init.d脚本和Upstart命令),systemctl命令比服务更通用:

sudo systemctl restart NetworkManager.service

网络图标(再次)应该消失一会儿,要查看其他systemctl选项,可以参考Systemd入门教程。

这是在Linux机器上处理网络的另一种工具,这是一个非常强大的工具,我觉得非常实用,许多系统管理员都喜欢它,因为它易于使用。

此方法有两个步骤:关闭网络,然后重新打开网络:

sudo nmcli networking off

网络将关闭,图标将消失,要重新打开它:

sudo nmcli networking on

此命令直接处理网络接口,将其状态更改为可以或不可以传输和接收数据的状态,它是Linux中必须知道的网络命令之一。

要关闭所有网络接口,请使用ifdown:

sudo ifdown -a

使用ifup重新打开所有网络接口:

sudo ifup -a

注意:此方法不会使系统托盘中的网络图标消失,但你将无法进行任何类型的连接。

Ubuntu 16.04网络配置(静态IP)

打开虚拟机编辑/etc/network/interfaces文件

root@swift:/home/swift# cat /etc/network/interfaces

# This file describes the network interfaces available on your system

# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface

auto lo

iface lo inet loopback

# The primary network interface

auto ens33#16.04的命名为ens33不是eth0

iface ens33 inet static#static表示静态

address 192.168.110.111    #IP地址

netmask 255.255.255.0    #子网掩码

gateway 192.168.110.2    #网关

dns-nameservers 61.139.2.69    #DNS

root@swift:/home/swift# /etc/init.d/networking restart

[ ok ] Restarting networking (via systemctl): networking.service.

root@swift:/home/swift#ping -c 4

PING (180.97.33.108) 56(84) bytes of data.

64 bytes from 180.97.33.108: icmp_seq=1 ttl=128 time=51.1 ms

64 bytes from 180.97.33.108: icmp_seq=2 ttl=128 time=48.9 ms

64 bytes from 180.97.33.108: icmp_seq=3 ttl=128 time=49.4 ms

64 bytes from 180.97.33.108: icmp_seq=4 ttl=128 time=51.3 ms

--- ping statistics ---

4 packets transmitted, 4 received, 0% packet loss, time 3006ms

rtt min/avg/max/mdev = 48.966/50.215/51.304/1.041 ms

root@swift:/home/swift#

到此配置完成可以连接网络进行安装和更新了。

如果重启服务后还是不能连接网络

编辑/etc/resolvconf/resolv.conf.d/目录下的base  head两个文件

在末尾追加DNS

例如:

nameserver 61.139.2.69#使用当地网络服务商提供的DNS

修改后重启网络服务或重启虚拟机(reboot、init 6、shutdown -r now等多种方法)。

ubuntu系统网络配置&ssh配置

该配置环境为ubuntu16.04.2

(一) 网络配置

安装完成系统后网络配置如下:

第一步:ifconfig -a 查看有几个网卡

如下截图表示有四个网卡

第二步:找出接线网卡

执行命令:ifconfig +网卡 up

例:up 第一个网卡enp4s0f0

ifconfig enp4s0f0 up

然后执行命令: ethtool enp4s0f0  查看Link状态,如下截图:

如果是yes表示该网卡已经接线 ,尝试手动配置ip(配置方法请见下一步骤)。如果是no,继续ifconfig up其他网卡,直到找到yes的为止。如果全部是no,请检查网线是否接好

第三步:配置网卡ip(只有临时作用,再次重启服务器配置会失效)

命令:ifconfig enp11s0f1 10.57.23.13/25

说明:配置网卡 enp11s0f1  IP为10.57.23.13 掩码是25位。即255.255.255.128

配置好截图如下:

第四步:检测连通性

尝试ping 网关,如果网关不通,表示直连不通,请检查网线和配置。网关通,接着配置默认路由,见第五步

第五步:配置路由(临时,重启后失效)

route add default gw 10.57.23.1 (默认配置这一条后,内网可以正常访问),如果不能,添加如下明细:

route add -net 10.0.0.0/8 gw 10.57.23.1

route add -net 192.168.0.0/16 gw 10.57.23.1

route add -net 172.16.0.0/12 gw 10.57.23.1

route add -net 100.64.0.0/10 gw 10.57.23.1

第六步:写入配置文件(永久)

注:一定要写入配置文件

ubuntu为何不直接在最开始写入配置文件里。因为ubuntu直接写入配置文件,不重启服务器貌似不生效(个人经验)

vim /etc/network/interfaces 可以直接在这里修改,具体配置如下:

# This file describes the network interfaces available on your system

# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface

auto lo

iface lo inet loopback

# The primary network interface

auto enp11s0f1     

iface enp11s0f1 inet static

address 10.57.23.13

netmask 255.255.255.128

gateway 10.57.23.1

####添加路由,这样网卡服务重启之后这些路由就会加载

up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.57.23.1

up route add -net 192.168.0.0 netmask 255.255.0.0 gw 10.57.23.1

up route add -net 172.16.0.0 netmask 255.240.0.0 gw 10.57.23.1

up route add -net 100.64.0.0 netmask 255.192.0.0 gw 10.57.23.1

重启网卡服务之后,配置的路由会自动加载,如下:

(二) 修改ssh 配置文件

ubuntu系统安装,默认是禁止root直接登录的

vim /etc/ssh/sshd_config

修改:PermitRootLogin yes

然后重启ssh服务 /etc/init.d/ssh restart

未经允许不得转载:便宜VPS网 » ubuntu服务器配置网络(ubuntu 服务器 联网)