{"id":20140601,"url":"https://github.com/goffinet/virt-scripts","last_synced_at":"2025-04-09T18:35:43.008Z","repository":{"id":52307376,"uuid":"53475664","full_name":"goffinet/virt-scripts","owner":"goffinet","description":"Bash scripts for Linux KVM labs. Only for educational purposes.","archived":false,"fork":false,"pushed_at":"2021-06-13T09:06:34.000Z","size":482,"stargazers_count":128,"open_issues_count":1,"forks_count":50,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-23T20:37:18.884Z","etag":null,"topics":["bash","centos","debian","kali-linux","kcli","kickstart","kvm","libvirt","libvirtd","preseed","qemu-kvm","ubuntu","virt-scripts","virtualization"],"latest_commit_sha":null,"homepage":"https://linux.goffinet.org/administration/virtualisation-kvm/","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goffinet.png","metadata":{"files":{"readme":"README.hetzner.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":["https://leanpub.com/b/linux-administration-complet"]}},"created_at":"2016-03-09T06:58:37.000Z","updated_at":"2025-02-17T03:57:16.000Z","dependencies_parsed_at":"2022-08-27T05:41:48.303Z","dependency_job_id":null,"html_url":"https://github.com/goffinet/virt-scripts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goffinet%2Fvirt-scripts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goffinet%2Fvirt-scripts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goffinet%2Fvirt-scripts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goffinet%2Fvirt-scripts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goffinet","download_url":"https://codeload.github.com/goffinet/virt-scripts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248088531,"owners_count":21045730,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","centos","debian","kali-linux","kcli","kickstart","kvm","libvirt","libvirtd","preseed","qemu-kvm","ubuntu","virt-scripts","virtualization"],"created_at":"2024-11-13T21:52:45.785Z","updated_at":"2025-04-09T18:35:42.979Z","avatar_url":"https://github.com/goffinet.png","language":"Shell","readme":"# Connect public IPv4 addresses, IPv4 and IPv6 subnets on Hetzner servers\n\n\u003eHow can I assign VMs with public ips that I have rented out from ISP (currently Hetzner) ?\n\nhttps://github.com/goffinet/virt-scripts/issues/4\n\nYou can deploy directly your VMs with IP adresses rented from Hetzner for example :\n\n1. assign dynamically to one VM a single public IPv4 address\n2. assign dynamically public IPv4 addresses within a subnet to many VMs\n3. assign public IPv6 within the default /64 subnet to many VMs\n\nThere is two steps for this for procedure, for all cases :\n\n1. Create a connexion (a bridge) with a physical interface ;\n2. Connect the VM to this bridge.\n\nIn the following example, the virtualization host is rented in a Hetzner DC. The root IPv4/IPv6 addresses are assigned on the `enp2s0` interafce with the `5.9.156.152` value for IPv4 and `2a01:4f8:190:44bb::2/64` for the IPv6 public address. The default IPv6 subnet is `2a01:4f8:190:44bb::/64` with `fe80::1` as default gateway.\n\n## First case : assign dynamically to one VM a single public IPv4 address\n\nA provider like Hetzner can offer one single public IPv4 address linked with a specific MAC address generated. Only the VM using this MAC will get this IPv4 address. In the Hetzner network, a DHCP service attributes the corresponding IP address.\n\nIn my case, I obtained `5.9.156.151` linked with the `00:50:56:00:7F:E0` MAC address.\n\nConsider that your guest is called \"`guest1`\" and that you want add an interface with the generated MAC address to obtain your new single public IP.\n\nFirst, we create a L2 bridge connected to a physical NIC, the root interface `enp2s0`, this bridge is called `hetzner1`. We use the `add-bridge-l2.sh` to do it with ease :\n\n```\n./add-bridge-l2.sh hetzner1 enp2s0\n```\n\nIn the next step, we attach a new vNIC to our VM with the MAC address from Hetzner, connected on the new bridge `hetzner1` :\n\n```\n./add-nic.sh guest1 hetzner1 00:50:56:00:7F:E0\n```\n\nThe device is succesfully attached :\n\n```\nDevice attached successfully\n\n Interface   Type     Source   Model    MAC\n-----------------------------------------------------------\n vnet0       bridge   virbr0   virtio   52:54:00:00:ff:40\n macvtap0    direct   enp2s0   virtio   00:50:56:00:7f:e0\n```\n\nInside your guest, the new interface will get the public IP by DHCP.\n\nYou can use this connection for IPv6 subnets also (See below).\n\nIf you want to deploy a native VM connected on the right bridge with the correct mac address on the first interafce, you can use the `define-guest-image-by-profile.sh` script like this :\n\n```bash\n./define-guest-image-by-profile.sh server1 hetzner1 big centos7 00:50:56:00:7F:E0\n```\n\n## Second case : assign dynamically public IPv4 addresses within a subnet to many VMs\n\nIn the following example, we will create a new router (bridge) that forwards the IPv4 trafic to `5.9.214.208/29` to your server from the Internet and that forwards the trafic from this subnet to the Internet. The router attributes IPv4 adresses (without network and broadcast adresses) :\n\n```\n./add-bridge-l3.sh hetzner2 ip4_dhcp 5.9.214.208 255.255.255.248 5.9.156.152\n```\n\nAnd you attach two new guests like `guest2` and `guest3` :\n\n```\nfor x in 2 3 ; do ./add-nic.sh guest$x hetzner2 ; done\n```\n\n## Third case : assign public IPv6 within the default /64 subnet to many VMs\n\nTo enable the default IPv6 subnet for your VMs, we simply create a L2 bridge and we attach the VMs. In this example, the root interface is `enp2s0`. The IPv6 range varies between `2a01:4f8:190:44bb::2` and `2a01:4f8:190:44bb:ffff:ffff:ffff:ffff`.\n\n```\n./add-bridge-l2.sh ipv6-bridge enp2s0\n```\n\nWe attach the `guest4` VM to this bridge :\n\n```\n./add-nic.sh guest4 ipv6-bridge\n```\n\nIn this case, we must configure manually the IPv6 connexion inside our VMs, for example :\n\n```\nip -6 add add 2a01:4f8:190:44bb::0100/64 dev eth1\nip -6 route add default via fe80::1 dev eth1\n```\n","funding_links":["https://leanpub.com/b/linux-administration-complet"],"categories":["Shell"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoffinet%2Fvirt-scripts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoffinet%2Fvirt-scripts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoffinet%2Fvirt-scripts/lists"}