0

I'm trying to set up a lab computer as a ssh server following this guide. One of the steps is setting up a static IP address. So, I was glad to find this answer. Following it, I created /etc/netplan/50-cloud-init.yaml file, pasted

network:
    ethernets:
        enp0s3:
            addresses: [desired_ip_address/24]
            gateway4: my_router_ip_address
            dhcp4: no
            nameservers:
              addresses: [1.1.1.1,8.8.8.8]
            optional: true
    version: 2

and run

sudo ip addr flush my_ethernet_num
sudo systemctl restart networking.service

where my_ethernet_num == enp9s0. Buuuut, after this ip a showed no ip address for the Ethernet:

svyatoslav@svyatoslav-desktop ~> ip a                                    (base) 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp9s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether a8:a1:59:4b:e8:bb brd ff:ff:ff:ff:ff:ff
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:f3:38:2f:33 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever

and sudo lshw -C network yielded *-network DISABLED. Then I tried to use that guide (section 'Static IP Address Assignment'). I created /etc/netplan/99_config.yaml, pasted the necessary code, run sudo netplan apply. Nothing changed except that I STOPPED SEEING wired connections in network settings... I tried the answer from here, and the 'Wired' section returned. But I can't change anything (for example, I can't pick 'Manual' option).

Screenshot

So, the questions are: how can I return the ability of changing it (in order to follow one more guide), or is there any other solution that will succeed in setting static ip address?...

--EDIT from 12/05/2021--

Here are all of my .yaml files showed by ls -al /etc/netplan:

01-network-manager-all.yaml:

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager

50-cloud-init.yaml:

network:
  ethernets:
    enp0s3:
      adresses: [192.168.0.116/24]
      gateway: 93.175.20.231
      dhcp4: no
      nameservers:
        addresses: [1.1.1.1,8.8.8.8]
      optional: true
  version: 2

99_config.yaml:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses:
        - 192.168.0.116/24
      gateway4: 192.168.0.1
      nameservers:
        search: [mydomain, otherdomain]
        addresses: [192.168.0.1, 8.8.8.8]
10
  • 1
    Probably you should delete/revert all changes that you have made, to get back to the original configuration. Then just use "Manual" option from the GUI. No need to mess with configuration files manually.
    – raj
    Nov 29, 2021 at 12:44
  • @raj, thank you for your comment! If I only knew how to revert all the changes... By the way, after rebooting, I suddenly found out that I can make changes to the settings! So, I'll try the the GUI option and write about results :) Nov 29, 2021 at 13:31
  • Why does your .yaml use enp0s3, when your interface is enp9s0? Are you using a Server or Desktop installation?
    – heynnema
    Nov 29, 2021 at 23:37
  • @heynnema, because it was in the answer for 'How do I set a static IP in Ubuntu?'. As we can see, enp0s25 is used in the question, but then enp0s3 is used in the answer, so I thought that it always must be enp0s25. > Are you using a Server or Desktop installation? I would like to use a Desktop installation, but I don't know concretely which one I was using... Is there any difference? I tried to follow Desktop installation but I could get confused. Dec 1, 2021 at 19:31
  • @TopCoder2000 Your network can't possibly be working with enp0s3 in the .yaml file. It needs to be enp9s0. But if you're using a Desktop installation, then your .yaml is all wrong anyway. A Desktop installation has a GUI, a Server installation is CLI only. Also, your self-accepted answer doesn't really make a lot of sense.
    – heynnema
    Dec 1, 2021 at 19:37

1 Answer 1

1

Pick ONE of the following two configurations...


Server installation with static IP...

Delete /etc/netplan/01-network-manager-all.yaml

Delete /etc/netplan/50-cloud-init.yaml

Edit /etc/netplan/99_config.yaml to look EXACTLY like this...

Note: regarding 192.168.0.116, make sure this address is outside of the DHCP range set in your router, and is not already used elsewhere.

Note: For DNS nameservers, settle on servers from one source... Google, Cloudflare, OpenDNS, etc. (3 max).

network:
  version: 2
  renderer: networkd
  ethernets:
    enp9s0:
      addresses: [192.168.0.116/24]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [192.168.0.1, 8.8.8.8]
      optional: true

sudo netplan generate

sudo netplan apply

reboot


Desktop installation with static IP...

Delete /etc/netplan/50-cloud-init.yaml

Delete /etc/netplan/99_config.yaml

Edit /etc/netplan/01-network-manager-all.yaml to look EXACTLY like this...

Note: Use the NetworkManager GUI to setup your static IP for "Wired Connection".

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager

sudo netplan generate

sudo netplan apply

reboot


Note: See https://netplan.io/examples/ for examples and design info about netplan.

5
  • Thank you for your answer and netplan examples! Now ip a shows correct output. But how do I setup a static IP with NetworkManager GUI? Dec 6, 2021 at 18:28
  • @TopCoder2000 Firstly, you can't use both parts of my answer at the same time. It's part 1 or part 2. If you're using part 2, then my answer says "Use the NetworkManager GUI to setup your static IP for "Wired Connection"". See the IPv4 tab. Click on the manual button. Fill in the address, mask, gateway, and DNS servers, and turn off DNS Auto.
    – heynnema
    Dec 6, 2021 at 18:44
  • yes, I remember! I'll accept it as soon as I don't have any questions :) Yes, I'm using the second option. But you also wrote yesterday that 'Static IPs should be set to be outside of the DHCP range set in the router'. But how do I know that set? For example, the second answer from here says that we have to check DHCP server configuration... Dec 7, 2021 at 6:51
  • @TopCoder2000 You must log into the admin page of your router and find the DHCP server settings. For your computer's static IP, you'll need to pick an address outside of the DHCP server's range of addresses.
    – heynnema
    Dec 7, 2021 at 15:01
  • Ah, good! Thanks! Dec 9, 2021 at 7:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .