Modify service dhcp-server name server

I would like to change the name server in:

service dhcp-server shared-network-name LAN subnet s.s.s.0/24

I have tried to edit and delete 1.1.1.1 and 9.9.9.9 and both commands fail. I would like to set the name server to s.s.s.1. I am missing something on how to do this.

The tree looks like this

vyos@vyos# show service dhcp-server
shared-network-name LAN {
subnet s.s.s.0/24 {
default-router s.s.s.1
domain-name foo.net
lease 3600
name-server 1.1.1.1
name-server 9.9.9.9
range 10 {
start s.s.s.183
stop s.s.s.193
}
static-mapping system1 {
ip-address s.s.s.188
mac-address xx:xx:xx:xx:xx:xx
}
}
}

Couple of things:

a) What version of Vyos
b) What’s the actual error you see, can you paste the config, a copy of a “show” command showing the the +/- bits of the config, and then the error you’re actually seeing?

Version of Vyos

vyos@vyos:~$ show version
Version:          VyOS 1.4-rolling-202212130326
Release train:    current

Built by:         autobuild@vyos.net
Built on:         Tue 13 Dec 2022 03:26 UTC
Build UUID:       f64b6613-642b-48f1-8e7c-1cbb7c8f8f87
Build commit ID:  f56f9f9d7bc169

Architecture:     x86_64
Boot via:         installed image
System type:      KVM guest

Hardware vendor:  QEMU
Hardware model:   Standard PC (Q35 + ICH9, 2009)
Hardware S/N:
Hardware UUID:    6a64d363-6735-4f02-b4ed-31c59b1b5060

Copyright:        VyOS maintainers and contributors

error I am seeing, I scrubbed the IP addresses ETC.

[edit]
vyos@vyos# edit service dhcp-server shared-network-name LAN
[edit service dhcp-server shared-network-name LAN]
vyos@vyos# show
 subnet s.s.s.0/24 {
     default-router s.s.s.1
     domain-name foo.net
     lease 3600
     name-server w.w.w.w
     name-server x.x.x.x
     range 10 {
         start s.s.s.183
         stop s.s.s.193
     }
     static-mapping VZ-ROUTER {
         ip-address s.s.s.188
         mac-address aa:aa:aa:aa:aa:aa
     }
 }
[edit service dhcp-server shared-network-name LAN]
vyos@vyos# set name-server s.s.s.1

  Set failed

[edit service dhcp-server shared-network-name LAN]
vyos@vyos#

“Set failed” usually indicates a problem with your Vyos instance where you’ve tried to modify the config as root and broken things.

Are you able to make other changes to the config, or does every attempt to change a line of config result in “Set failed”? You can try to modify a description somewhere, does it allow you to do that?

I tested changing a description and it failed. When my WAN IP changes I have a cron job run under root that deletes and updates my config. I am sure this is the issue. Question can I move this to user vyos and will it work?

below is the script section that does the variable setup to change config. Again this is run under root.

#!/bin/vbash
#set variables for wan interface, lan interface and destination MAC address
WANIF=eth0.100
LANIF=eth0.173
LANVIF="eth0 vif 173"
DMAC=mm:mm:mm:mm:mm:mm

#get gateway IP address from changeip and set it to variable IP
IP=$(curl --silent ip.changeip.com |grep -oE -m1 '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
#printf "\nGW IP = $IP\n"

#Set up to run vyos config and show commands
source /opt/vyatta/etc/functions/script-template
configure

I moved the scrip to user vyos, set ownership to vyos:users, chmod to 777 and it won’t run under user vyos. How do I execute the script under user vyos?

Usually adding this solves the issue:

#To make sure that a script is not accidentally called without the vyattacfg group, the script can be safeguarded like this:
if [ "$(id -g -n)" != 'vyattacfg' ] ; then
    exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@"
fi

Ref: Command Scripting Docs

1 Like

@n.fort Thanks for the pointer. Because I am still a neophyte at scripting I am wondering where I would add this if statement in my code. Should I do it just above the source /opt/… statement? I did change my cron job to run like this:

0 4 * * * sg vyattacfg -c /home/vyos/ckgwip_vlan.sh

Reading your link it states a reboot would fix the root edit issue. I rebooted and it did.

1 Like