Google’s Cloud NAT gateway

Thanks to Yuvraaj at crave.io for the following

Google launched something called Cloud NAT Gateway that charges for bandwidth to do NAT. It makes it more expensive to run than going with external IP (at least in the low volumes that I do). I found this blog entry by Yuvraaj at Crave.io that allows you to enable NAT in a few steps. I’ve documented the commands below so I can refer to them in the future if I need them and in case the crave.io blog entry is no longer available or I can’t find it for some reason.

Create or edit this file/script that runs everytime the machine is booted

/etc/rc.local
#!/bin/bash

set -x

# Turn on IP forwarding
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
# Turn on the route
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Setup Route in GCP Routing table

gcloud compute routes create no-ip-internet-route --network default --destination-range 0.0.0.0/0 --next-hop-instance nat-gateway --next-hop-instance-zone us-west1-b --tags no-ip --priority 800

Setup networking tags for VMs that need this

gcloud compute instances add-tags <existing-instance> --tags no-ip

Bash script to check if a process is running and if failed, restart it

Thanks to Karson for this one.

Create a file:

sudo nano ./run.sh

#!/bin/sh
if ps -ef | grep -v grep | grep boinc ; then
exit 1
else
sudo systemctl restart boinc-client &
exit 0
fi

Change permissions

sudo chmod +x ./run.sh

Make it run automatically

crontab -e

Every second

* * * * * /home/user/run.sh

It’s always DNS

For the longest time I’ve had this issue where I had to add a . (period) to the end of a hostname to ping it. Today was the day I put that to rest.

Reading online it has to do with how Windows handles hostnames via NetBIOS vs DNS (or lack thereof). What I could never figure out was why it was happening to only 1 of my 2 Windows servers.

On the first Windows Server, I can ping “lara” fine. On the second Windows Server, I have to ping “linah.” in order to get to it.

Fix

I went into my pihole and updated all the local DNS entries from hostname to fully qualified domain names. So lara became lara.local.adrianng.com and linah became linah.local.adrianng.com. Then I entered CNAME records pointing lara to lara.local.adrianng.com and linah to linah.local.adrianng.com. ipconfig /flushdns later and now everything works the way it should.

Including my domain name in there is probably not necessary. It might have even worked if I just entered lara.local as the hostname instead of just lara (although some posts advise against using .local because apple uses that for hello or something).

There are still weird observations… some hosts are still resolving lara to lara.local instead of lara.local.adrianng.com but at least they can ping it.

Edit:
Don’t think the CNAMEs have anything to do with it. It’s the Primary DNS suffix setting in windows and adding local.adrianng.com to the search list that’s making this work. Either specifying it in Computer Name, or adding it to the TCP/IP v4 advanced settings.

Windows Server 2022 upgrade notes

Upgraded Windows Server 2019 to Server 2022 today. I RDP’ed in and mounted iso and setup from within windows. It downloads some updates and performs some installation steps within windows. Took 10-20 minutes to get to 100% then you have to click a button for it to restart. At that point the RDP session terminates obviously. Plug in monitor and keyboard. The restart takes quite a while with nothing on the screen. Eventually windows logon screen is showed and you set up the country etc.

Evaluation Version doesn’t support in place upgrades
The option to keep files/settings is greyed out when upgrading from Windows Server 2019 Eval to Windows Server 2022 Eval.
The only option available is to keep nothing.
To do in place upgrades while retaining files/settings, you must have a fully licensed Windows Server.

Set Computer Name and DNS suffix

Set timezone

Set IP address
Install Hyper V Manager
Setup vswitch VLAN ID
Set static IP and default gateway on vswitch nic
Default gateway was prefilled/greyed out but going in a second time shows a blank default gateway.

Allow Core Network Diagonistics in Firewall to enable ping echos
Edit rule to specify which subnets to respond to, by default it’s only local subnet

Enable RDP
Allow Remote Connections to this computer

Install BOINC
Exit BOINC
Copy boinc data folder contents to c:\programdata\boinc
Restart BOINC
Do sychronization
Confirm tasks and host list