Setup hostname so it appears in the router

Setup hostname so it appears in the router

Postby mpparsley123 » Thu Dec 10, 2020 8:44 am

We should configure the network to communicate the hostname to the router when asking for an ip (dhcp).

This is what I normally do but it isn't sufficient:
Code: Select all
sudo vi /etc/hostname

Delete the old name and setup new name.

Code: Select all
sudo vi /etc/hosts

Replace any occurrence of the existing computer name with your new one.

When I type
Code: Select all
hostname
I get the correct name but it still doesn't appear in my router.

hostnamectl isn't available.

Perhaps someone could point out where the dhcpd config/command lives so we can add the hostname in there?

So far, I found this:
Code: Select all
# ps aux | grep dhcp
root      1305  0.0  0.3   3652   964 ?        Ss   10:11   0:00 /sbin/udhcpc -b -i eth0 -s /etc/api/api_dhcpc.php dhcpdCbScript


We could add -h to add the hostname.

Code: Select all
   -x OPT:VAL      Include option OPT in sent packets (cumulative)
            Examples of string, numeric, and hex byte opts:
            -x hostname:bbox - option 12
            -x lease:3600 - option 51 (lease time)
            -x 0x3d:0100BEEFC0FFEE - option 61 (client id)
   -F,--fqdn NAME      Ask server to update DNS mapping for NAME
   -C,--clientid-none   Don't send MAC as client identifier


I tested this command and it works, the hostname now appears in my router:
Code: Select all
/sbin/udhcpc -b -i eth0 -s /etc/api/api_dhcpc.php dhcpdCbScript -h MYHOSTNAME


Adding an option to the ifconfig command would work too.

Both are initialised in /etc/init.d/rcS.
The
Last edited by mpparsley123 on Thu Dec 10, 2020 11:36 am, edited 1 time in total.
mpparsley123
Donator VIP
Donator VIP
 
Posts: 15
Joined: Sat Nov 28, 2020 11:32 am

Re: Setup hostname so it appears in the router

Postby Jocko » Thu Dec 10, 2020 11:11 am

Hi

Yes these options are not used by the fw and we can add these additional options but why do you want to hide the nas mac address on the router level. This may occurs issue on the wol feature which requires it
Jocko
Site Admin - expert
 
Posts: 11367
Joined: Tue Apr 12, 2011 4:48 pm
Location: Orleans, France

Re: Setup hostname so it appears in the router

Postby Jocko » Thu Dec 10, 2020 11:12 am

About rcS script, I advice to create a cron boot script (see the related menu) instead of editing it directly
Jocko
Site Admin - expert
 
Posts: 11367
Joined: Tue Apr 12, 2011 4:48 pm
Location: Orleans, France

Re: Setup hostname so it appears in the router

Postby mpparsley123 » Thu Dec 10, 2020 11:21 am

It's not that I want to hide the mac address but I want to show the hostname (in my router).

In fact adding "-h HOSTNAME" would be sufficient (just tested that).

Thanks for the tip about cron. Would enabling cron mean that the disk can no longer go to sleep (assuming that the default setup provides some kind of sleep)?

edit: I had another look at /etc/rcS and it seems that udhcp is part of busybox and is initiated in/etc/finc/laniffunc_configure.finc.

I changed this line:
Code: Select all
./laniffunc_configure.finc:197:         if (mwexec("/sbin/udhcpc -b -i " . escapeshellarg($lanif) . " -s {$g['etc_path']}/api/api_dhcpc.php dhcpdCbScript") != 0){

to
Code: Select all
./laniffunc_configure.finc:197:         if (mwexec("/sbin/udhcpc -b -i " . escapeshellarg($lanif) . " -s {$g['etc_path']}/api/api_dhcpc.php dhcpdCbScript -h {$HOSTNAME}") != 0){


Now I can no longer ping the disk, I get why you said to change it in a cron :-)

PS: Wouldn't it be better to use a config file for this so we could change settings like this:
Code: Select all
echo $'opt hostname $HOSTNAME\nopt domain local' > /etc/udhcpd.conf
mpparsley123
Donator VIP
Donator VIP
 
Posts: 15
Joined: Sat Nov 28, 2020 11:32 am

Re: Setup hostname so it appears in the router

Postby Jocko » Thu Dec 10, 2020 12:59 pm

mpparsley123 wrote:Wouldn't it be better to use a config file for this so we could change settings like this:
udhcpc is a busybox applet which dos not use a conf file like udhcp.conf as you can read in this output
Code: Select all
strace  -f udhcpc -i bond0 -s /truc.sh
execve("/sbin/udhcpc", ["udhcpc", "-i", "bond0", "-s", "/truc.sh"], [/* 14 vars */]) = 0
brk(0)                                  = 0xf6000
uname({sys="Linux", node="Acrab.local", ...}) = 0
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=29692, ...}) = 0
mmap2(NULL, 29692, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb6fa9000
close(3)                                = 0
open("/lib/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\300;\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=652816, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6fd6000
mmap2(NULL, 684168, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6f01000
mprotect(0xb6fa0000, 28672, PROT_NONE)  = 0
mmap2(0xb6fa7000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x9e) = 0xb6fa7000
close(3)                                = 0
open("/usr/lib/libtirpc.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0(P\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=113804, ...}) = 0
mmap2(NULL, 146520, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6edd000
mprotect(0xb6ef8000, 32768, PROT_NONE)  = 0
mmap2(0xb6f00000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b) = 0xb6f00000
close(3)                                = 0
open("/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\260^\1\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1250504, ...}) = 0
mmap2(NULL, 1291656, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6da1000
mprotect(0xb6ed0000, 28672, PROT_NONE)  = 0
mmap2(0xb6ed7000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x12e) = 0xb6ed7000
mmap2(0xb6eda000, 9608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6eda000
close(3)                                = 0
open("/lib/libnsl.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\260.\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=71552, ...}) = 0
mmap2(NULL, 112376, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6d85000
mprotect(0xb6d96000, 28672, PROT_NONE)  = 0
mmap2(0xb6d9d000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x10) = 0xb6d9d000
mmap2(0xb6d9f000, 5880, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6d9f000
close(3)                                = 0
open("/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0lF\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=88048, ...}) = 0
mmap2(NULL, 127520, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6d65000
mprotect(0xb6d7a000, 28672, PROT_NONE)  = 0
mmap2(0xb6d81000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14) = 0xb6d81000
mmap2(0xb6d83000, 4640, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6d83000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6fd5000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6fd4000
set_tls(0xb6fd44c0, 0xb6fd891c, 0xb6fd4b98, 0xb6fd44c0, 0xb6fd8000) = 0
mprotect(0xb6ed7000, 8192, PROT_READ)   = 0
mprotect(0xb6d81000, 4096, PROT_READ)   = 0
mprotect(0xb6d9d000, 4096, PROT_READ)   = 0
mprotect(0xb6fa7000, 4096, PROT_READ)   = 0
mprotect(0xb6fd7000, 4096, PROT_READ)   = 0
munmap(0xb6fa9000, 29692)               = 0
set_tid_address(0xb6fd4068)             = 7785
set_robust_list(0xb6fd4070, 0xc)        = 0
futex(0xbe9b9cb4, FUTEX_WAKE_PRIVATE, 1) = 0
futex(0xbe9b9cb4, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, NULL, b6d82000) = -1 EAGAIN (Resource temporarily unavailable)
rt_sigaction(SIGRTMIN, {0xb6d6914c, [], SA_SIGINFO|0x4000000}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0xb6d68fe8, [], SA_RESTART|SA_SIGINFO|0x4000000}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM_INFINITY}) = 0
getuid32()                              = 0
socket(PF_INET, SOCK_RAW, IPPROTO_RAW)  = 3
ioctl(3, SIOCGIFINDEX, {ifr_name="bond0", ifr_index=8}) = 0
ioctl(3, SIOCGIFHWADDR, {ifr_name="bond0", ifr_hwaddr=00:d0:4b:91:1f:2f}) = 0
close(3)                                = 0
brk(0)                                  = 0xf6000
brk(0x117000)                           = 0x117000
open("/dev/null", O_RDWR|O_LARGEFILE)   = 3
close(3)                                = 0
write(1, "udhcpc (v1.21.0) started\n", 25udhcpc (v1.21.0) started
) = 25
pipe([3, 4])                            = 0
fcntl64(3, F_SETFD, FD_CLOEXEC)         = 0
fcntl64(4, F_SETFD, FD_CLOEXEC)         = 0
fcntl64(4, F_GETFL)                     = 0x1 (flags O_WRONLY)
fcntl64(4, F_SETFL, O_WRONLY|O_NONBLOCK) = 0
rt_sigaction(SIGUSR1, {0x4a5f0, [USR1], SA_RESTART|0x4000000}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGUSR2, {0x4a5f0, [USR2], SA_RESTART|0x4000000}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGTERM, {0x4a5f0, [TERM], SA_RESTART|0x4000000}, {SIG_DFL, [], 0}, 8) = 0
gettimeofday({1607604840, 338094}, NULL) = 0
vfork(Process 7786 attached
)                                 = 7786
[pid  7785] wait4(7786, Process 7785 suspended
 <unfinished ...>
[pid  7786] execve("/truc.sh", ["/truc.sh", "deconfig"], [/* 15 vars */]) = -1 EACCES (Permission denied)
[pid  7786] exit_group(111)             = ?
Process 7785 resumed
Process 7786 detached
<... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 111}], 0, NULL) = 7786
--- SIGCHLD (Child exited) @ 0 (0) ---
socket(PF_PACKET, SOCK_DGRAM, 8)        = 5
bind(5, {sa_family=AF_PACKET, proto=0x800, if8, pkttype=0xf /* ? */, addr(0)={15024, }, 20) = 0
setsockopt(5, SOL_SOCKET, SO_ATTACH_FILTER, "\t\0\0\0008\243\f\0", 8) = 0
setsockopt(5, SOL_PACKET, PACKET_AUXDATA, [1], 4) = 0
fcntl64(5, F_SETFD, FD_CLOEXEC)         = 0
socket(PF_INET, SOCK_RAW, IPPROTO_RAW)  = 6
ioctl(6, SIOCGIFINDEX, {ifr_name="bond0", ifr_index=8}) = 0
ioctl(6, SIOCGIFHWADDR, {ifr_name="bond0", ifr_hwaddr=00:d0:4b:91:1f:2f}) = 0
close(6)                                = 0
gettimeofday({1607604840, 374457}, NULL) = 0
write(1, "Sending discover...\n", 20Sending discover...
)   = 20
socket(PF_PACKET, SOCK_DGRAM, 8)        = 6
bind(6, {sa_family=AF_PACKET, proto=0x800, if8, pkttype=PACKET_HOST, addr(6)={0, ffffffffffff}, 20) = 0
sendto(6, "E\0\0014\0\0\0\0@\21y\272\0\0\0\0\377\377\377\377\0D\0C\1 U1\1\1\6\0"..., 308, 0, {sa_family=AF_PACKET, proto=0x800, if8, pkttype=PACKET_HOST, addr(6)={0, ffffffffffff}, 20) = 308
close(6)                                = 0
fcntl64(5, F_SETFD, FD_CLOEXEC)         = 0
gettimeofday({1607604840, 429501}, NULL) = 0
select(6, [3 5], NULL, NULL, {3, 0})    = 1 (in [5], left {2, 999988})
recvmsg(5, {msg_name(0)=NULL, msg_iov(1)=[{"E\20\1\10\231\322@\0@\6\242\v\177\0\0\1\177\0\0\1\37\220\257\242\357I8\357\2\257?<"..., 656}], msg_controllen=32, {cmsg_len=32, cmsg_level=SOL_PACKET, cmsg_type=, ...}, msg_flags=0}, 0) = 264
gettimeofday({1607604840, 432269}, NULL) = 0
fcntl64(5, F_SETFD, FD_CLOEXEC)         = 0
gettimeofday({1607604840, 433701}, NULL) = 0
select(6, [3 5], NULL, NULL, {3, 0})    = 1 (in [5], left {2, 999990})
recvmsg(5, {msg_name(0)=NULL, msg_iov(1)=[{"E\0\0004V\252@\0@\6\346\27\177\0\0\1\177\0\0\1\257\242\37\220\2\257?<\357I9\303"..., 656}], msg_controllen=32, {cmsg_len=32, cmsg_level=SOL_PACKET, cmsg_type=, ...}, msg_flags=0}, 0) = 52
gettimeofday({1607604840, 436869}, NULL) = 0
fcntl64(5, F_SETFD, FD_CLOEXEC)         = 0
gettimeofday({1607604840, 438236}, NULL) = 0
select(6, [3 5], NULL, NULL, {3, 0})    = 1 (in [5], left {2, 963596})
recvmsg(5, {msg_name(0)=NULL, msg_iov(1)=[{"E\300\1u\0\0@\0@\21\265\3\300\250\1\1\300\250\1c\0C\0D\1a\260\24\2\1\6\0"..., 656}], msg_controllen=32, {cmsg_len=32, cmsg_level=SOL_PACKET, cmsg_type=, ...}, msg_flags=0}, 0) = 373
gettimeofday({1607604840, 478146}, NULL) = 0
fcntl64(5, F_SETFD, FD_CLOEXEC)         = 0
socket(PF_INET, SOCK_RAW, IPPROTO_RAW)  = 6
ioctl(6, SIOCGIFINDEX, {ifr_name="bond0", ifr_index=8}) = 0
ioctl(6, SIOCGIFHWADDR, {ifr_name="bond0", ifr_hwaddr=00:d0:4b:91:1f:2f}) = 0
close(6)                                = 0
gettimeofday({1607604840, 483254}, NULL) = 0
write(1, "Sending select for 192.168.1.99."..., 35Sending select for 192.168.1.99...
) = 35
socket(PF_PACKET, SOCK_DGRAM, 8)        = 6
bind(6, {sa_family=AF_PACKET, proto=0x800, if8, pkttype=PACKET_HOST, addr(6)={0, ffffffffffff}, 20) = 0
sendto(6, "E\0\1@\0\0\0\0@\21y\256\0\0\0\0\377\377\377\377\0D\0C\1,g[\1\1\6\0"..., 320, 0, {sa_family=AF_PACKET, proto=0x800, if8, pkttype=PACKET_HOST, addr(6)={0, ffffffffffff}, 20) = 320
close(6)                                = 0
fcntl64(5, F_SETFD, FD_CLOEXEC)         = 0
gettimeofday({1607604840, 539786}, NULL) = 0
select(6, [3 5], NULL, NULL, {3, 0})    = 1 (in [5], left {2, 900841})
recvmsg(5, {msg_name(0)=NULL, msg_iov(1)=[{"E\300\1u\0\0@\0@\21\265\3\300\250\1\1\300\250\1c\0C\0D\1a\255\24\2\1\6\0"..., 656}], msg_controllen=32, {cmsg_len=32, cmsg_level=SOL_PACKET, cmsg_type=, ...}, msg_flags=0}, 0) = 373
gettimeofday({1607604840, 642432}, NULL) = 0
write(1, "Lease of 192.168.1.99 obtained, "..., 49Lease of 192.168.1.99 obtained, lease time 86400
) = 49
vfork(Process 7787 attached
)                                 = 7787
[pid  7785] wait4(7787, Process 7785 suspended
 <unfinished ...>
[pid  7787] execve("/truc.sh", ["/truc.sh", "bound"], [/* 28 vars */]) = -1 EACCES (Permission denied)
[pid  7787] exit_group(111)             = ?
Process 7785 resumed
Process 7787 detached
<... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 111}], 0, NULL) = 7787
--- SIGCHLD (Child exited) @ 0 (0) ---
close(5)                                = 0
open("/dev/null", O_RDWR|O_LARGEFILE)   = 5
clone(Process 7788 attached
child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb6fd4068) = 7788
[pid  7785] exit_group(0)               = ?
set_robust_list(0xb6fd4070, 0xc)        = 0
setsid()                                = 7788
dup2(5, 0)                              = 0
dup2(5, 1)                              = 1
dup2(5, 2)                              = 2
close(5)                                = 0
gettimeofday({1607604840, 697313}, NULL) = 0
select(4, [3], NULL, NULL, {43200, 0}
mpparsley123 wrote:edit: I had another look at /etc/rcS and it seems that udhcp is part of busybox and is initiated in/etc/finc/laniffunc_configure_NIC.finc:
I go to send you an updated file
be aware if there is an issue on this file you lose any remote access on the nas
Jocko
Site Admin - expert
 
Posts: 11367
Joined: Tue Apr 12, 2011 4:48 pm
Location: Orleans, France

Re: Setup hostname so it appears in the router

Postby mpparsley123 » Thu Dec 10, 2020 1:02 pm

be aware if there is an issue on this file you lose any remote access on the nas

Whoops, too late for that :-)

Is there a way to mount a new disk and restart from scratch or should I just throw it all away?
mpparsley123
Donator VIP
Donator VIP
 
Posts: 15
Joined: Sat Nov 28, 2020 11:32 am

Re: Setup hostname so it appears in the router

Postby Jocko » Thu Dec 10, 2020 1:08 pm

How did you install the firmware ? Did you use fvdw-sl console ?
Jocko
Site Admin - expert
 
Posts: 11367
Joined: Tue Apr 12, 2011 4:48 pm
Location: Orleans, France

Re: Setup hostname so it appears in the router

Postby mpparsley123 » Thu Dec 10, 2020 1:09 pm

I installed the fvdw-sl firmware using the fvdw-sl console from a windows pc onto my cloudbox. See viewtopic.php?f=28&t=3431
mpparsley123
Donator VIP
Donator VIP
 
Posts: 15
Joined: Sat Nov 28, 2020 11:32 am

Re: Setup hostname so it appears in the router

Postby Jocko » Thu Dec 10, 2020 1:12 pm

So please around 15' so that I send you the update file and we go to use fvdw-sl console to overwrite your edited file (I assume only laniffunc_configure.finc)
Jocko
Site Admin - expert
 
Posts: 11367
Joined: Tue Apr 12, 2011 4:48 pm
Location: Orleans, France

Re: Setup hostname so it appears in the router

Postby mpparsley123 » Thu Dec 10, 2020 1:13 pm

I edited both these files:

root@MYNAS:/etc/finc # grep -rnw ./ -e "dhcpdCbScript"
./laniffunc_configure_NIC.finc:43: if (mwexec("/sbin/udhcpc -b -i '$lanif' -s {$g['etc_path']}/api/api_dhcpc.php dhcpdCbScript -h {$HOSTNAME}") != 0){
./laniffunc_configure.finc:197: if (mwexec("/sbin/udhcpc -b -i " . escapeshellarg($lanif) . " -s {$g['etc_path']}/api/api_dhcpc.php dhcpdCbScript") != 0){
mpparsley123
Donator VIP
Donator VIP
 
Posts: 15
Joined: Sat Nov 28, 2020 11:32 am

Next

Return to Development

Who is online

Users browsing this forum: No registered users and 3 guests