-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from ResidenciaTICBrisa/connect-to-nao
Conecta máquina virtual aos NAOv4 e NAOv6
- Loading branch information
Showing
10 changed files
with
372 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
source './env-vars.sh' | ||
|
||
chmod -v 0755 /usr/lib/qemu/qemu-bridge-helper | ||
rm -v /etc/qemu/bridge.conf | ||
|
||
sysctl "net.ipv4.conf.${BRIDGE}.forwarding=0" | ||
sysctl "net.ipv6.conf.${BRIDGE}.forwarding=0" | ||
|
||
ip link set "${BRIDGE}" down | ||
ip link delete "${BRIDGE}" type bridge | ||
|
||
nft delete table inet "${QEMU_NAT_TABLE}" | ||
nft delete table inet "${QEMU_FILTER_TABLE}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
|
||
source './env-vars.sh' | ||
|
||
abort_if_iproute2_not_found | ||
abort_if_nftables_not_found | ||
abort_if_interface_not_found | ||
|
||
chmod -v 4755 /usr/lib/qemu/qemu-bridge-helper | ||
printf 'allow %s\n' "${BRIDGE}" > /etc/qemu/bridge.conf | ||
chmod -v 0644 /etc/qemu/bridge.conf | ||
|
||
ip link add "${BRIDGE}" type bridge | ||
ip link set "${BRIDGE}" up | ||
# Must be in a different network than your current one | ||
ip address add "${BRIDGE_IP}" dev "${BRIDGE}" | ||
|
||
sysctl "net.ipv4.conf.${BRIDGE}.forwarding=1" | ||
sysctl "net.ipv6.conf.${BRIDGE}.forwarding=1" | ||
|
||
nft add table inet "${QEMU_FILTER_TABLE}" | ||
nft add chain inet "${QEMU_FILTER_TABLE}" input '{ type filter hook input priority filter; }' | ||
nft add chain inet "${QEMU_FILTER_TABLE}" output '{ type filter hook output priority filter; }' | ||
nft add chain inet "${QEMU_FILTER_TABLE}" forward '{ type filter hook forward priority filter; policy drop; }' | ||
nft add rule inet "${QEMU_FILTER_TABLE}" forward iifname "${BRIDGE}" oifname "${INTERFACE}" log accept | ||
nft add rule inet "${QEMU_FILTER_TABLE}" forward ct state related,established log accept | ||
|
||
nft add table inet "${QEMU_NAT_TABLE}" | ||
nft add chain inet "${QEMU_NAT_TABLE}" postrouting '{ type nat hook postrouting priority srcnat; policy accept; }' | ||
nft add chain inet "${QEMU_NAT_TABLE}" prerouting '{ type nat hook prerouting priority dstnat; policy accept; }' | ||
nft add chain inet "${QEMU_NAT_TABLE}" output '{ type nat hook output priority -100; policy accept; }' | ||
nft add rule inet "${QEMU_NAT_TABLE}" postrouting oifname "${INTERFACE}" log masquerade | ||
|
||
dnsmasq --interface="${BRIDGE}" --bind-interfaces --dhcp-range="${DNSMASQ_IP_START},${DNSMASQ_IP_END},${DNSMASQ_IP_MASK}" --no-daemon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
source './env-vars.sh' | ||
|
||
echo "Booting machine '${VM_NAME}' with HDD and packages' disk" | ||
|
||
abort_if_bios_not_found | ||
|
||
abort_if_disk_not_found | ||
|
||
qemu-system-x86_64 \ | ||
-k pt-br \ | ||
-machine "${MACHINE_CFG}" \ | ||
-cpu "${CPU_MODEL}" -smp "${CPU_NUMBER}" \ | ||
-m "${MACHINE_MEMORY_SIZE}" \ | ||
-L "${BIOS_LOCATION}" \ | ||
-device virtio-scsi-pci,id=scsi0 \ | ||
-drive file="${DISK_LOCATION}",format=qcow2,if=none,media=disk,index=0,id=drive-hd0,readonly=off \ | ||
-device scsi-hd,bus=scsi0.0,drive=drive-hd0,id=hd0,bootindex=0 \ | ||
-device qemu-xhci \ | ||
-boot menu=on \ | ||
-netdev bridge,id=net0,br="${BRIDGE}" \ | ||
-device virtio-net-pci,netdev=net0,mac="${VM_MAC}" \ | ||
-rtc base=localtime,clock=vm \ | ||
-device "${DISPLAY_DEVICE}" \ | ||
-display "${DISPLAY_BACKEND}" \ | ||
-monitor stdio \ | ||
-name "${VM_NAME}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
source './env-vars.sh' | ||
|
||
chmod -v 0755 /usr/lib/qemu/qemu-bridge-helper | ||
rm -v /etc/qemu/bridge.conf | ||
|
||
sysctl "net.ipv4.conf.${BRIDGE}.forwarding=0" | ||
sysctl "net.ipv6.conf.${BRIDGE}.forwarding=0" | ||
|
||
ip link set "${BRIDGE}" down | ||
ip link delete "${BRIDGE}" type bridge | ||
|
||
nft delete table inet "${QEMU_NAT_TABLE}" | ||
nft delete table inet "${QEMU_FILTER_TABLE}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
|
||
source './env-vars.sh' | ||
|
||
abort_if_iproute2_not_found | ||
abort_if_nftables_not_found | ||
abort_if_interface_not_found | ||
|
||
chmod -v 4755 /usr/lib/qemu/qemu-bridge-helper | ||
printf 'allow %s\n' "${BRIDGE}" > /etc/qemu/bridge.conf | ||
chmod -v 0644 /etc/qemu/bridge.conf | ||
|
||
ip link add "${BRIDGE}" type bridge | ||
ip link set "${BRIDGE}" up | ||
# Must be in a different network than your current one | ||
ip address add "${BRIDGE_IP}" dev "${BRIDGE}" | ||
|
||
sysctl "net.ipv4.conf.${BRIDGE}.forwarding=1" | ||
sysctl "net.ipv6.conf.${BRIDGE}.forwarding=1" | ||
|
||
nft add table inet "${QEMU_FILTER_TABLE}" | ||
nft add chain inet "${QEMU_FILTER_TABLE}" input '{ type filter hook input priority filter; }' | ||
nft add chain inet "${QEMU_FILTER_TABLE}" output '{ type filter hook output priority filter; }' | ||
nft add chain inet "${QEMU_FILTER_TABLE}" forward '{ type filter hook forward priority filter; policy drop; }' | ||
nft add rule inet "${QEMU_FILTER_TABLE}" forward iifname "${BRIDGE}" oifname "${INTERFACE}" log accept | ||
nft add rule inet "${QEMU_FILTER_TABLE}" forward ct state related,established log accept | ||
|
||
nft add table inet "${QEMU_NAT_TABLE}" | ||
nft add chain inet "${QEMU_NAT_TABLE}" postrouting '{ type nat hook postrouting priority srcnat; policy accept; }' | ||
nft add chain inet "${QEMU_NAT_TABLE}" prerouting '{ type nat hook prerouting priority dstnat; policy accept; }' | ||
nft add chain inet "${QEMU_NAT_TABLE}" output '{ type nat hook output priority -100; policy accept; }' | ||
nft add rule inet "${QEMU_NAT_TABLE}" postrouting oifname "${INTERFACE}" log masquerade | ||
|
||
dnsmasq --interface="${BRIDGE}" --bind-interfaces --dhcp-range="${DNSMASQ_IP_START},${DNSMASQ_IP_END},${DNSMASQ_IP_MASK}" --no-daemon |
Oops, something went wrong.