mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-11 04:26:38 +00:00
39 lines
1.2 KiB
Text
39 lines
1.2 KiB
Text
|
#!/bin/bash
|
||
|
# Copyright 2022 The Chromium OS Authors. All rights reserved.
|
||
|
# Use of this source code is governed by a BSD-style license that can be
|
||
|
# found in the LICENSE file.
|
||
|
|
||
|
# Set up networking on the host using a TAP device. This probably works on
|
||
|
# many ubuntu or debian machines, but highly depends on the existing network
|
||
|
# configuration.
|
||
|
|
||
|
TAP_USER=$USER
|
||
|
HOST_DEV=$(ip route get 8.8.8.8 | awk -- '{printf $5}')
|
||
|
SUBNET=192.168.10.1/24
|
||
|
|
||
|
setup_network() {
|
||
|
sudo ip tuntap add mode tap user "$TAP_USER" vnet_hdr crosvm_tap
|
||
|
sudo ip addr add "$SUBNET" dev crosvm_tap
|
||
|
sudo ip link set crosvm_tap up
|
||
|
|
||
|
sudo sysctl net.ipv4.ip_forward=1
|
||
|
sudo iptables -t nat -A POSTROUTING -o "${HOST_DEV}" -j MASQUERADE
|
||
|
sudo iptables -A FORWARD -i "${HOST_DEV}" -o crosvm_tap -m state --state RELATED,ESTABLISHED -j ACCEPT
|
||
|
sudo iptables -A FORWARD -i crosvm_tap -o "${HOST_DEV}" -j ACCEPT
|
||
|
}
|
||
|
|
||
|
echo "This will set up a tap device 'crosvm_tap' using the $SUBNET"
|
||
|
echo "network range, routed through /dev/${HOST_DEV}."
|
||
|
echo
|
||
|
echo "It will run the following commands:"
|
||
|
echo
|
||
|
type setup_network | sed '1,3d;$d'
|
||
|
echo
|
||
|
read -p "Continue [y/N]? " -r
|
||
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
set -ex
|
||
|
setup_network
|