您尚未登录。

#1 2014-05-01 19:55:42

dxcqcv
会员
注册时间: 2012-12-28
帖子: 239

关于使用systemd设置静态ip失败

用wiki里的方法,设置静态ip,分别是
/etc/conf.d/network@interface
address=192.168.0.15
netmask=24
broadcast=192.168.0.255
gateway=192.168.0.1

/etc/systemd/system/network@.service
[Unit]
Description=Network connectivity (%i)
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device

[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/network@%i

ExecStart=/usr/bin/ip link set dev %i up
ExecStart=/usr/bin/ip addr add ${address}/${netmask} broadcast ${broadcast} dev %i
ExecStart=/usr/bin/sh -c 'test -n ${gateway} && /usr/bin/ip route add default via ${gateway}'

ExecStop=/usr/bin/ip addr flush dev %i
ExecStop=/usr/bin/ip link set dev %i down

[Install]
WantedBy=multi-user.target

# systemctl enable network@interface.service
# systemctl start network@interface.service

enalbe正常,start收到错误信息:
A dependency job for network@interface.service failed
查看journalctl -xn中高亮的错误信息为
Job sys-subsystem-net-devices-interface.device/start time out
Time out waiting for device sys-subsystem-net-device-interface.device
Dependency failed for Network connecting (interface)

补充:我用手动添加静态IP可以,就是每次重启就要重来一次


learning Arch linux

离线

#2 2014-05-01 20:00:25

依云
会员
所在地: a.k.a. 百合仙子
注册时间: 2011-08-21
帖子: 8,485
个人网站

Re: 关于使用systemd设置静态ip失败

interface 换成你的网卡设备名,如 wlan0 之类的。

离线

#3 2014-05-01 20:30:47

dxcqcv
会员
注册时间: 2012-12-28
帖子: 239

Re: 关于使用systemd设置静态ip失败

#ip a后得到设备名为enp3s0
#mv /etc/conf.d/network@interface /etc/conf.d/network@enp3s0
# systemctl enable network@enp3s0.service
# systemctl start network@enp3s0.service

报错,Job for network@enp3s0.service failed
查看#systemctl status network@enp3s0.service后得到高亮错误提示为
network@enp3s0.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Failed to start Network connecting (enp3s0)
Unit network@enp3s0.service entered failed state


learning Arch linux

离线

#4 2014-05-01 21:30:10

依云
会员
所在地: a.k.a. 百合仙子
注册时间: 2011-08-21
帖子: 8,485
个人网站

Re: 关于使用systemd设置静态ip失败

好像是因为 systemd 不解释 ${xxx} 表示的环境变量。试试去掉 {}?或者包一层 sh -c。

离线

#5 2014-05-02 07:24:28

dxcqcv
会员
注册时间: 2012-12-28
帖子: 239

Re: 关于使用systemd设置静态ip失败

好的,我试试,有点奇怪的是上面一行变量出错,但下面一行变量是成功的,完成出错信息如下

network@enp3s0.service -Network connecting (enp3s0)
Loaded: locaded(/etc/systemd/system/network@.service; enabled)
Active: failed(Result: exit-code) since time...
Process: 28993 ExecStart=/usr/bin/ip addr add ${address}/${netmask} broadcast ${broadcast} dev %i (code=exited, status=2)
Process: 28991 ExecStart=/usr/bin/ip link set dev %i up (code=exited, status=0/SUCCESS)
Main PID: 28993(code=exited, status=2)

Time... Localhost ip[28993]: RTNETLINK answers: File exists
network@enp3s0.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Failed to start Network connecting (enp3s0)
Unit network@enp3s0.service entered failed state

learning Arch linux

离线

#6 2014-05-02 15:09:21

依云
会员
所在地: a.k.a. 百合仙子
注册时间: 2011-08-21
帖子: 8,485
个人网站

Re: 关于使用systemd设置静态ip失败

ip[28993]: RTNETLINK answers: File exists

你的网卡已经有地址了?

离线

#7 2014-05-08 01:40:04

糊涂
本尊
注册时间: 2012-10-30
帖子: 203

Re: 关于使用systemd设置静态ip失败

看的什么wiki啊?不要搞什么conf.d

# cd /etc/netctl
# cp example/ethernet-static enp3s0
# vi enp3s0
Description='A basic static ethernet connection'
Interface=enp3s0
Connection=ethernet
IP=static
Address=('192.168.1.1/24')
Gateway='192.168.1.254'
DNS='202.106.0.20'
[esc]:wq
# systemctl stop dhcpcd
# systemctl disable dhcpcd
# netctl enable enp3s0
# netctl start enp3s0

搞定!

最近编辑记录 糊涂 (2014-05-08 02:22:20)


想装X,别装X

离线

#8 2014-05-08 01:56:44

糊涂
本尊
注册时间: 2012-10-30
帖子: 203

Re: 关于使用systemd设置静态ip失败


想装X,别装X

离线

页脚