启动时设置IP

Monday, Mar 13, 2017 | 1 minute read | Updated at Monday, Mar 13, 2017

@
启动时设置IP

update-rc.d

  • the script (setipaddr.sh)
#! /bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:$PATH
ifconfig eth0 192.168.10.1/24
  • update-rc.d setting
chmod +x setipaddr.sh
mv setipaddr.sh /etc/init.d
update-rc.d setipaddr.sh defaults
  • run level
# If defaults is used then update-rc.d will make links to start the service in runlevels 2345 and to stop the service in runlevels 016
runlevel # get current level

systemctl

  • service file (/etc/systemd/system/setipaddr.service)
[Unit]
Description=set ip on boot
After=network.target

[Service]
Type=oneshot
ExecStart=/opt/bin/setipaddr.sh

[Install]
WantedBy=multi-user.target
  • systemctl setting
systemctl enable setipaddr.service

© 2016 - 2025 Caisong's Blog

🌱 Powered by Hugo with theme Dream.

About Me

大龄程序员,喜欢折腾各种环境部署、软件应用。

博客记录日常。