#!/bin/bash # Get clean Debian installation ready for use in GNS3 user='debian' pass='debian' ttyS0_service='/lib/systemd/system/ttyS0.service' # Check if I am root [ "$(id -u)" != 0 ] && echo "Run the script as root, exiting" && exit 1 # Update packages apt-get update [ "$?" != 0 ] && echo "System can't be updated, exiting" && exit 1 # Check if we utilities are installed - net-tools to manage interfaces instead netplan for package in net-tools vim; do dpkg --list | grep "$package" &>/dev/null [ "$?" == 1 ] && sudo apt-get -y install "$package" done # Check if ipv4 and ipv6 forwarding are enabled" ipv4_fwd="$(sysctl net.ipv4.ip_forward | cut -d ' ' -f3)" ipv6_fwd="$(sysctl net.ipv6.conf.all.forwarding | cut -d ' ' -f3)" if [ "$ipv4_fwd" == 0 ]; then sysctl -w net.ipv4.ip_forward=1 sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf echo "I have enabled IPv4 forwarding" elif [ "$ipv4_fwd" == 1 ]; then echo "IPv4 forwarding is enabled between interfaces, nothing to do" else echo "IPv4 forwarding between interfaces is not enabled, exiting" exit 1 fi if [ "$ipv6_fwd" == 0 ]; then sysctl -w net.ipv6.conf.all.forwarding=1 sed -i 's/#net.ipv6.conf.all.forwarding/net.ipv6.conf.all.forwarding/g' /etc/sysctl.conf echo "I have enabled IPv6 forwarding" elif [ "$ipv6_fwd" == 1 ]; then echo "IPv6 forwarding is enabled between interfaces, nothing to do" else echo "IPv6 forwarding between interfaces is not enabled, exiting" exit 1 fi # Stop renaming interface e.g. eth0 to ens3 sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"/g' /etc/default/grub grub-mkconfig -o /boot/grub/grub.cfg # Redirect video output to serial console echo '[Unit]' > "$ttyS0_service" echo -e "Description=Serial Console Service\n" >> "$ttyS0_service" echo '[Service]' >> "$ttyS0_service" echo 'ExecStart=/sbin/getty -L 115200 ttyS0 vt102' >> "$ttyS0_service" echo -e "Restart=always\n" >> "$ttyS0_service" echo '[Install]' >> "$ttyS0_service" echo 'WantedBy=multi-user.target' >> "$ttyS0_service" systemctl daemon-reload systemctl enable ttyS0 systemctl start ttyS0 # Reduce timeout for network interfaces to 15sec during boot mkdir -p /etc/systemd/system/networking.service.d echo "[Service]" > /etc/systemd/system/networking.service.d/reduce-timeout.conf echo "TimeoutStartSec=15" >> /etc/systemd/system/networking.service.d/reduce-timeout.conf # Add path to .bashrc echo 'export PATH=$PATH:/usr/local/sbin:/usr/sbin:/usr/bin' >> /home/$user/.bashrc # Print login credential before login echo \n >> echo "Username/password: $user/$pass" >> /etc/issue exit 0