在 Ubuntu 系统中,getconf 命令主要用于查询系统配置信息,但它本身并不直接提供网络配置的详细信息。如果你想获取网络配置,可以使用其他命令,比如 ip, ifconfig, nmcli 等。
使用 ip 命令:
ip addr show
ip addr 简写为 ip a。使用 ifconfig 命令(在较新的系统中可能已被 ip 命令取代):
sudo ifconfig (需要安装 net-tools 包)
```。
使用 nmcli 命令:
nmcli connection show
nmcli connection show --active
nmcli connection show <connection-name>
```。
使用 nmcli 工具:
nmcli connection show
nmcli connection add type ethernet con-name MyEthernet ifname eth0
nmcli connection modify MyEthernet ipv4.addresses 192.168.1.10/24 nmcli connection modify MyEthernet ipv4.gateway 192.168.1.1 nmcli connection modify MyEthernet ipv4.dns 8.8.8.8
nmcli connection up MyEthernet
```。
使用 ip 命令:
sudo ip addr add 192.168.1.10/24 dev eth0
sudo ip link set eth0 up
```。
编辑网络配置文件:
sudo netplan --debug generate cat /etc/netplan/*.yaml
sudo nano /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.10/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
sudo netplan apply
```。
使用 ifconfig 和 route 命令(不推荐):
sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0
sudo route add default gw 192.168.1.1 eth0
```。
请注意,ifconfig 命令在一些新版本的 Ubuntu 中可能已被 ip 命令取代,因此建议使用 ip 命令进行网络配置。