Score:0

How do I set a static IP in Ubuntu 20.04.3 LTS?

ธง pk

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]
raj avatar
cn flag
raj
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.
TopCoder2000 avatar
pk flag
@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 :)
heynnema avatar
ru flag
Why does your .yaml use enp0s3, when your interface is enp9s0? Are you using a Server or Desktop installation?
TopCoder2000 avatar
pk flag
@heynnema, because it was in the answer for ['How do I set a static IP in Ubuntu?'](https://askubuntu.com/questions/766131/how-do-i-set-a-static-ip-in-ubuntu/767693#767693). 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.
heynnema avatar
ru flag
@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 avatar
ru flag
@TopCoder2000 How many .yaml files do you have in /etc/netplan? Show me `ls -al /etc/netplan`.
TopCoder2000 avatar
pk flag
Thank you for you willingness to help, @heynnema! > Also, your self-accepted answer doesn't really make a lot of sense Why? When should I accept the answer then? > How many .yaml files do you have in /etc/netplan? Here is the output `total 28 drwxr-xr-x 2 root root 4096 ноя 29 11:45 ./ drwxr-xr-x 153 root root 12288 дек 5 14:15 ../ -rw-r--r-- 1 root root 104 авг 5 2019 01-network-manager-all.yaml -rw-r--r-- 1 root root 204 ноя 29 11:45 50-cloud-init.yaml -rw-r--r-- 1 root root 239 ноя 29 11:07 99_config.yaml` P. S. how do I make a new line in comments?..
heynnema avatar
ru flag
@TopCoder2000 Ah! You have 3 .yaml files... and I'll bet they're conflicting. Edit your question and show me ALL .yaml files, WITHOUT redactions, and then I can come up with an answer for you. You can't make a new line in comments... that's why data like that belongs as an edit to your question. Your answer, below, doesn't answer your question and solve your problem... that's why I said it really makes no sense.
TopCoder2000 avatar
pk flag
@heynnema, has edited :) Where is it easily explained what netplan is and what .yaml files do? I want to have a superficial understanding.
heynnema avatar
ru flag
@TopCoder2000 Status please...
Score:0
ธง ru

เลือกหนึ่งในสองการกำหนดค่าต่อไปนี้...


การติดตั้งเซิร์ฟเวอร์ด้วย Static IP...

ลบ /etc/netplan/01-network-manager-all.yaml

ลบ /etc/netplan/50-cloud-init.yaml

แก้ไข /etc/netplan/99_config.yaml เพื่อให้มีลักษณะเช่นนี้ ...

บันทึก: เกี่ยวกับ 192.168.0.116 ตรวจสอบให้แน่ใจว่าที่อยู่นี้อยู่นอกช่วง DHCP ที่ตั้งไว้ในเราเตอร์ของคุณ และไม่ได้ถูกใช้ที่อื่นแล้ว

บันทึก: สำหรับเนมเซิร์ฟเวอร์ DNS ตั้งค่าบนเซิร์ฟเวอร์จากแหล่งเดียว... Google, Cloudflare, OpenDNS ฯลฯ (สูงสุด 3 รายการ)

เครือข่าย:
  รุ่น: 2
  เรนเดอร์: เครือข่าย
  อีเธอร์เน็ต:
    enp9s0:
      ที่อยู่: [192.168.0.116/24]
      เกตเวย์ 4: 192.168.0.1
      เนมเซิร์ฟเวอร์:
        ที่อยู่: [192.168.0.1, 8.8.8.8]
      ตัวเลือก: จริง

sudo netplan สร้าง

ใช้ sudo netplan

รีบูต


การติดตั้งเดสก์ท็อปด้วย IP แบบคงที่...

ลบ /etc/netplan/50-cloud-init.yaml

ลบ /etc/netplan/99_config.yaml

แก้ไข /etc/netplan/01-network-manager-all.yaml เพื่อให้มีลักษณะเช่นนี้ ...

บันทึก: ใช้ NetworkManager GUI เพื่อตั้งค่า IP แบบคงที่ของคุณสำหรับ "Wired Connection"

# ให้ NetworkManager จัดการอุปกรณ์ทั้งหมดในระบบนี้
เครือข่าย:
  รุ่น: 2
  เรนเดอร์: NetworkManager

sudo netplan สร้าง

ใช้ sudo netplan

รีบูต


บันทึก: ดู https://netplan.io/examples/ สำหรับตัวอย่างและข้อมูลการออกแบบเกี่ยวกับ netplan

TopCoder2000 avatar
pk flag
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?
heynnema avatar
ru flag
@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.
TopCoder2000 avatar
pk flag
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](https://www.quora.com/How-can-I-find-the-number-of-available-IP-addresses-in-my-DHCP) says that we have to check DHCP server configuration...
heynnema avatar
ru flag
@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.
TopCoder2000 avatar
pk flag
Ah, good! Thanks!

โพสต์คำตอบ

คนส่วนใหญ่ไม่เข้าใจว่าการถามคำถามมากมายจะปลดล็อกการเรียนรู้และปรับปรุงความสัมพันธ์ระหว่างบุคคล ตัวอย่างเช่น ในการศึกษาของ Alison แม้ว่าผู้คนจะจำได้อย่างแม่นยำว่ามีคำถามกี่ข้อที่ถูกถามในการสนทนา แต่พวกเขาไม่เข้าใจความเชื่อมโยงระหว่างคำถามและความชอบ จากการศึกษาทั้ง 4 เรื่องที่ผู้เข้าร่วมมีส่วนร่วมในการสนทนาด้วยตนเองหรืออ่านบันทึกการสนทนาของผู้อื่น ผู้คนมักไม่ตระหนักว่าการถามคำถามจะมีอิทธิพลหรือมีอิทธิพลต่อระดับมิตรภาพระหว่างผู้สนทนา