#!/bin/bash
# 设置主机名
function set_hostname() {
echo "请输入新的主机名:"
read hostname
sudo hostnamectl set-hostname $hostname
echo "主机名已修改为:$hostname"
}
# 设置IP地址
function set_ip() {
echo "请输入新的IP地址:"
read ip
echo "请输入新的子网掩码:"
read netmask
echo "请输入新的网关:"
read gateway
echo "请输入新的DNS服务器:"
read dns
sudo ifconfig eth0 $ip netmask $netmask
sudo route add default gw $gateway
echo "nameserver $dns" | sudo tee /etc/resolv.conf > /dev/null
echo "IP地址已修改为:$ip"
echo "子网掩码已修改为:$netmask"
echo "网关已修改为:$gateway"
echo "DNS服务器已修改为:$dns"
}
# 设置VLAN
function set_vlan() {
echo "请输入新的VLAN ID:"
read vlan_id
sudo vconfig add eth0 $vlan_id
sudo ifconfig eth0.$vlan_id up
echo "VLAN已修改为:$vlan_id"
}
# 主菜单
function main_menu() {
echo "请选择要执行的操作:"
echo "1. 修改主机名"
echo "2. 修改IP地址"
echo "3. 修改VLAN"
echo "4. 退出"
read choice
case $choice in
1) set_hostname ;;
2) set_ip ;;
3) set_vlan ;;
4) exit ;;
*) echo "无效的选择" ;;
esac
main_menu
}
# 启动虚拟机
echo "正在启动虚拟机..."
# 这里可以添加你启动虚拟机的命令
# 执行主菜单
main_menu