How to get netplan to replace sections instead of merge? - ubuntu-20.04

I am trying so set netplan so the yaml files only contain portions of the configuration.
The idea is to use a specific config file when a machine should use a specific DNS.
In order to do that, I have 2 yaml config files: /etc/netplan/01-netcfg.yaml and /etc/netplan/02-dns.yaml'
Their content is really simple.
/etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: true
dhcp6: false
optional: true
nameservers:
addresses: [4.2.2.1, 4.2.2.2, 208.67.220.220]
and /etc/netplan/02-dns.yaml:
network:
version: 2
renderer: networkd
ethernets:
eth0:
nameservers:
addresses: [1.1.1.1]
When I apply the configuration and check the DNS configuration, I get the following:
# systemd-resolve --status
Global
[...]
Current DNS Server: 4.2.2.1
DNS Servers: 4.2.2.1
4.2.2.2
208.67.220.220
[...]
Link 2 (eth0)
[...]
Current DNS Server: 4.2.2.1
DNS Servers: 4.2.2.1
4.2.2.2
208.67.220.220
1.1.1.1
10.0.2.3
So it appears that the configurations got 'cumulated': the DNS from the 02xxx file got added to the DNS from the 01xxx file (which makes sense...).
How to I get net plan to 'replace' instead of 'merge'?

Related

How to connect a bridge to a tunnel with netplan?

Well, before I asked this question, I searched a lot and couldn't find a proper answer (or the question was wrongly asked).
I want to connect a bridge to a GRE tunnel on netplan.
I can successfully do the connection, but the routing table doesn't get updated correctly. I am forced to add the route manually for it to work.
So, here's my netplan setup:
network:
version: 2
ethernets:
enp1s0f0:
dhcp4: no
accept-ra: false
addresses:
- 192.168.0.100/24
routes:
- to: default
via: 192.168.0.254
match:
macaddress: d8:5e:d3:43:cd:ae
set-name: enp1s0f0
nameservers:
addresses:
- 1.1.1.1
- 1.0.0.1
- 2606:4700:4700::1111
- 2606:4700:4700::1001
tunnels:
gre1:
mode: gre
remote: 192.168.100.150
local: 192.168.0.100
bridges:
br1:
dhcp4: false
dhcp6: false
optional: true
interfaces: [ gre1 ]
addresses:
- 172.16.20.2/30
routes:
- to: default
via: 172.16.20.1
scope: link
table: 100
routing-policy:
- from: 172.16.20.0/30
table: 100
With the above configuration, the gre1 has a state UNKNOWN and the br1 state is DOWN.
If I try to ping 172.16.20.1 it fails.
But, if I run:
ip route add 172.16.20.0/30 dev gre1
I can ping without any issues.
Anyone has a clue on how to solve this riddle?

Homestead ERR_SOCKET_NOT_CONNECTED After Mac OS Update

I recently updated to Big Sur on my Mac and haven't been able to access any of my VMs as web pages since. I've destroyed and rebuilt this VM using Homestead's expected installation process.
VirtualBox 6.1.28
Latest Homestead version from release branch
Vagrant 2.2.18
This is the error I'm seeing
After long hours spent researching this loads of people seem to resolve it by adding the site to their hosts file. To confirm I have added this to hosts:
Error when viewing the URL without site in hosts
Update: I'm able to view the VM if I go to http://localhost:8000/. Going to http://192.168.10.10 doesn't work.
From the vagrant box using curl 192.168.10.10 produces the expected HTML output of that page. So does curl localhost:8000 from my machine. If I try curl 192.168.10.10 from my machine I get curl: (55) getpeername() failed with errno 22: Invalid argument.
I've tried every other network configuration within Virtualbox and using NAT is the only one that allows the SSH connection. It seems requests aren't making it to the VirtualBox.. probably because there's an error stating the socket isn't connected.
Socket stats seems to show it's listening on port 80
As of now I have destroyed and rebuilt the box again, so it is as close to an expected installation that anyone should have.
p.s. "site.test" is a placeholder for the actual name.
Here is my Homestead.yaml: https://pastebin.com/qhPdWCNv
---
ip: "192.168.10.10"
memory: 2048
cpus: 2
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Sites
to: /home/vagrant/code/
sites:
- map: site.test
to: /home/vagrant/code/site/public
php: "7.4"
databases:
- homestead
features:
- mysql: true
- mariadb: false
- postgresql: false
- ohmyzsh: false
- webdriver: false
services:
- enabled:
- "mysql"
# - disabled:
# - "postgresql#11-main"
#ports:
# - send: 33060 # MySQL/MariaDB
# to: 3306
# - send: 4040
# to: 4040
# - send: 54320 # PostgreSQL
# to: 5432
# - send: 8025 # Mailhog
# to: 8025
# - send: 9600
# to: 9600
# - send: 27017
# to: 27017
Here is my hosts file: https://pastebin.com/Y6Re15iy
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
192.168.10.10 site.test
::1 localhost
Vagrant 6.1.28 seems to restrict the valid IP address of a guest.
Took me hours to figure this out, read then manual.
Solved by changing my Homestead.yaml ip to 192.168.56.0 and also altered the ip in /etc/hosts
From the manual:
On Linux, Mac OS X and Solaris Oracle VM VirtualBox will only allow IP addresses in 192.68.56.0/21 range to be assigned to host-only adapters.
For anyone that encounters this issue I fixed this by updating the VM to a new IP, changing the domain, and clearing the dns cache (dscacheutil –flushcache).

force Static IP on VM creation

I have an ansible script that connects to my Vcenter and builds out a VM. This works great assuming the network it will be built on has DHCP enabled. I am building mostly Centos 7 VM's on a network that does not have DHCP enabled meaning static IP's. The VM gets built, but then I am stuck logging into each VM manually and assigning the IP.
How can I tell CentOS to use a specific IP?
I am familiar with kickstart, but not sure how to trigger the install to pickup a ks file. (I know I can create a custom ISO, but I dont want to create a custom ISO for each VM I built.)
I have tried using the following flags on ansible VMware_guest module, but no luck.
Any Suggestions??
vmware_guest:
network:
type: static
ip: 192.168.1.5
mask: 255.255.255.0
gateway: 192.168.1.1
Please try using netmask instead of mask.
vmware_guest:
network:
name: "{{ network_name }}"
type: static
ip: 192.168.1.5
netmask: 255.255.255.0
gateway: 192.168.1.1

Hearbeat icmp configuration host aliases

I have a elastic stack (version 7.3.0) configured, with a Heartbeat set up to ping my different hosts.
The config file of my monitor looks like this:
- type: icmp
name: icmp_monitor
schedule: '#every 5s'
hosts:
- machine1.domain.com # Machine 1
- machine2.domain.com # Machine 2
- machine3.domain.com # Machine 3
Is there a way to give the hosts an "alias" in the configuration file ?
In my organisation, the server hostname is not very meaningfull, it would be great for example to specify that machine1.domain.com is MongoDB main server.
The example on the documentation page shows that you can set host names in the hosts section/key. There they specify "myhost". So I assume that it is possible to define any name you want.
Elasticsearch is however not responsible for aliasing/resolving hostnames. It is a task of your OS.
If your heartbeat runs on a Linux machine I would set the aliases in /etc/hosts like
192.168.1.X mongodb-main
and would set the alias in the monitor config like
- type: icmp
name: icmp_monitor
schedule: '#every 5s'
hosts:
- mongodb-main
and see if heartbeat accepts it and can resolve the alias/hostname.

How configure Homestead and xip.io?

I want to access from other devices (iphone, android device, etc) to my sites on homestead in my machine. My machine and all device are on same network.
I want to use http://xip.io but I could not confgure it.
My ip machine is 192.168.0.12
The ip for sites on Homestead is 192.168.10.10
This is the file hosts:
127.0.0.1 localhost
127.0.1.1 host
#Virtual Hosts on Homestead
192.168.10.10 siteOne.com
192.168.10.10 siteTwo.app
192.168.10.10 otherSite.app
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
and this is Homestead.yaml
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Homestead-Projects
to: /home/vagrant/Homestead-Projects
sites:
- map: siteOne.com
to: /home/vagrant/Homestead-Projects/SiteOne/public
- map: siteTwo.app
to: /home/vagrant/Homestead-Projects/SiteTwo/public
- map: otherSite.app
to: /home/vagrant/Homestead-Projects/OtherSite/public
databases:
- homestead
- db_siteOne
- db_siteTwo
- db_otherSite
variables:
- key: APP_ENV
value: local
# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar
# ports:
# - send: 93000
# to: 9300
# - send: 7777
# to: 777
# protocol: udp
how can I do it?
Thanks!
You can access your site by browsing to http://<your_local_ip>.xip.io:8000.
To understand how it works you need to know two facts:
Domain example.your_ip.xip.io resolves to your_ip.
By default local port 8000 is mapped to port 80 of your homestead virtual machine.
Please note, xip.io acts as a "DNS" and you don't need to edit your hosts file to access your homestead site from other devices on local network.
This solution works perfectly if you have only one site mapped in homestead. If there are multiple sites, only last mapped site gets served. A workaround is to use site identifier in your url. http://<your_site>.<your_local_ip>.xip.io:8000 still resolves to same endpoint but now you can update your homestead nginx to pickup the site identifier and serve the right site.
I believe Homestead already ships with it by default,
in my case i just added an entry on the hosts files, /etc/hosts (i'm on a mac machine), like this:
127.0.0.1 http://app.ip.address.xip.io:8000
(usually the default port is 8000), and then add an entry on the homestead yml config file (you can reach by typing homestead edit on your console.
and that should do it.

Resources