use /sbin/netconfig 命令更新/etc/resolv.conf文件

netconfig是用于设置网络环境的命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
haotianfei@tianfei-opensuse:/etc/sysconfig> sudo netconfig --help
Usage:
netconfig <global options>
netconfig <action> <action options>

actions:
modify Requires an interface and service specific settings via STDIN
or as file using the --input-file or --lease-file option.
Already existing settings for this interface and service will
be replaced with the new one, otherwise netconfig creates a
new state file. Finaly, netconfig updates the managed files.
remove Removes the interface and service specific settings and
updates the managed files.
update Updates the managed files with the current set of settings.
batch Executes a batch file with modify,remove,update action lines.
Unlike in regular actions, modify and remove do not call update.
modify options:
< -s|--service <service name> > service providing settings
[ -i|--interface <interface name> ] interface providing settings
[ -F|--input-format <input format> ] currently 'dhcpcd' supported only
[ -I|--input-file <file name> ] file name to read, stdin by default
[ -l|--lease-file <file name> ] alias for --input-file
[ -m|--module-only <name | prefix> ] module or module group updates only
[ -f|--force-replace ] generate files, even user modified
[ -v|--verbose ] enable debug and be verbose

remove options:
< -s|--service <service name> > service providing settings
[ -i|--interface <interface name> ] interface providing settings
[ -m|--module-only <name | prefix> ] module or module group updates only
[ -f|--force-replace ] generate files, even user modified
[ -v|--verbose ] enable debug and be verbose

update options:
[ -m|--module-only <name | prefix> ] module or module group updates only
[ -f|--force-replace ] generate files, even user modified
[ -v|--verbose ] enable debug and be verbose

batch options:
[ -B|--batch-file <file name> ] file name to read, stdin by default
[ -v|--verbose ] enable debug and be verbose

global options:
<-h|--help> show this help text

Active modules: dns-resolver dns-bind dns-dnsmasq nis ntp-runtime
Module groups : dns nis ntp

注意help中的update,如果网络配置不正常,可以使用netconfig update -f强制修复

1
2
3
4
5
6
7
haotianfei@tianfei-opensuse:/etc/sysconfig> sudo netconfig update
<13>Apr 1 09:53:46 dns-resolver: ATTENTION: You have modified /etc/resolv.conf. Leaving it untouched...
<13>Apr 1 09:53:46 dns-resolver: You can find my version in /etc/resolv.conf.netconfig
ATTENTION: You have modified /etc/resolv.conf. Leaving it untouched...
You can find my version in /etc/resolv.conf.netconfig ...
haotianfei@tianfei-opensuse:/etc/sysconfig> sudo netconfig update -f
<13>Apr 1 09:54:03 dns-resolver: force replace set: backup created as /etc/resolv.conf.20190401-095403
坚持原创技术分享,您的支持将鼓励我继续创作!