1

I have the following line which does not work:

ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=5 root@$serverip "echo 'nameserver 1.1.1.1' > /etc/resolv.conf && sudo systemctl restart resolvconf.service"

As I somehow need to put nameserver 1.1.1.1 in some other type of quoting here I guess. Can smb help?

1
  • The line works for me exactly as it is. What is not working for you? Jul 16, 2020 at 10:59

1 Answer 1

1

Just run cat /etc/resolv.conf.

$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN

Your command works. But your invokation of systemctl restart resolvconf overwrites your changes again. You need to configure resolvconf properly instead of writing to /etc/resolv.conf.

4
  • 1
    If i simply do: >>ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=5 root@$serverip echo 'nameserver 1.1.1.1' > /etc/resolv.conf<< I get back Bad port ''Server'
    – user200271
    Jul 16, 2020 at 11:11
  • That rather sounds like $serverip contains something wrong. Jul 16, 2020 at 11:18
  • The error message you get can be reproduced using the parameter -p Server. -p expects the port of the SSH server. Jul 16, 2020 at 11:28
  • Also came accross the xD pretty stupid ... Its working, now for me!
    – user200271
    Jul 17, 2020 at 17:15

You must log in to answer this question.