在Ubuntu From Scratch(UFS)项目中,配置网络是一个重要的步骤,以确保系统能够连接到外部网络并进行通信。以下是在Ubuntu系统中配置网络的一般步骤,这些步骤适用于大多数Ubuntu版本,包括从Scratch构建的系统。
编辑Netplan配置文件:
/etc/netplan/
目录下,例如01-netcfg.yaml
。sudo nano /etc/netplan/01-netcfg.yaml
配置静态IP:
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
应用配置:
sudo netplan apply
验证配置:
ip addr show enp0s3
ping google.com
打开网络设置:
编辑连接:
保存设置并重启网络:
验证配置:
ip addr show
或ping
命令检查网络状态。编辑配置文件:
sudo nano /etc/network/interfaces
配置静态IP:
auto enp0s3
iface enp0s3 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
重启网络服务:
sudo systemctl restart networking
验证配置:
ip addr show
或ping
命令验证配置是否生效。