在 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
命令進行網絡配置。