我正在运行 12.04 发行版。我正在寻找可以在服务器上以命令行方式运行的程序,以便我可以更改网络设置。类似的程序有network-admin
或,netconf
但这些程序需要图形界面,而我的服务器上没有图形界面。只有命令行。
有什么推荐的套餐吗?
编辑
我希望可以更改 IP 地址、DNS、网关等,并保存这些设置以供重启。我之前设置过静态 IP,ifconfig
但重启后似乎又恢复到了默认网络 IP。我删除了 GUI 以限制进程和占用的空间。我使用的嵌入式设备没有很大的存储空间。它实际上是一个 ARM 系统发行版。我进入文件/etc/network/interfaces
,似乎没有为主网络保存任何设置。我真的希望有一种简单的方法来实现这一点,比如地址 XXXX,它会采用网络地址而不是静态地址?如果这有意义的话。
答案1
我会建议nmcli
(手册页)。
它已经安装在 Ubuntu 上。
示例输出
tim@Hairy14:~$ nmcli -p c
======================================================================================================================
Connection list
======================================================================================================================
NAME UUID TYPE TIMESTAMP-REAL
----------------------------------------------------------------------------------------------------------------------
Tim's Phone Network 39bdb4e5-bce2-498e-ba2f-326e9601ea21 bluetooth never
Hotspot e9d19b97-a01e-4017-9f64-3f663f5a025b 802-11-wireless Mon 28 Jul 2014 10:56:02 BST
Tim's Phone Network e0f716d4-c84f-4cd0-8ff6-140471583bea bluetooth never
Wired Connection RIP 516797eb-78cf-4930-9d3a-b0be1b861f42 802-3-ethernet Wed 23 Jul 2014 12:01:28 BST
Wired connection SIP 57816f79-049b-4ecc-806c-c48278845fc2 802-3-ethernet Wed 30 Jul 2014 16:52:14 BST
选项:
tim@Hairy14:~$ nmcli
Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }
OPTIONS
-t[erse] terse output
-p[retty] pretty output
-m[ode] tabular|multiline output mode
-f[ields] <field1,field2,...>|all|common specify fields to output
-e[scape] yes|no escape columns separators in values
-n[ocheck] do not check nmcli and NetworkManager versions
-v[ersion] show program version
-h[elp] print this help
OBJECT
nm NetworkManager's status
c[onnection] NetworkManager's connections
d[evice] devices managed by NetworkManager
tim@Hairy14:~$ nmcli -p
Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }
OPTIONS
-t[erse] terse output
-p[retty] pretty output
-m[ode] tabular|multiline output mode
-f[ields] <field1,field2,...>|all|common specify fields to output
-e[scape] yes|no escape columns separators in values
-n[ocheck] do not check nmcli and NetworkManager versions
-v[ersion] show program version
-h[elp] print this help
OBJECT
nm NetworkManager's status
c[onnection] NetworkManager's connections
d[evice] devices managed by NetworkManager
因此要显示 nm 的状态:
nmcli -p nm
答案2
答案3
尝试使用您想要的 IP 设置编辑 /etc/network/interfaces 文件。示例
vi /etc/network/interfaces
你的文件看起来应该是这样的
## dh2 generated for "machine name" : 2014-07-09 15:37:35
# gateway address space is 'xxx'
# xxx.xxx.xxx.xxx
# assigned : "machine name" : machine :
iface eth0 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx
broadcast xxx.xxx.xxx.xxx
up route add -net x.x.x.x netmask x.x.x.x gw x.x.x.x dev eth0 || true
down route delete -net x.x.x.x netmask x.x.x.x gw x.x.x.x dev eth0 || true
up route add -net x.x.x.x netmask x.x.x.x gw x.x.x.x dev eth0 || true
down route delete -net x.x.x.x netmask x.x.x.x gw x.x.x.x dev eth0 || true
# loopback
iface lo inet loopback
# auto interfaces (all of them!)
auto eth0 lo