ubuntu-18.04自动配置脚本

使用ubuntu server的alternate installer版本

#!/bin/bash

echo "blacklist i2c_piix4"  >> /etc/modprobe.d/blacklist.conf

currentTime=$(date +"%Y-%m-%d_%H:%M:%S")

sed -i '/UseDNS yes/s/^/#/' /etc/ssh/sshd_config
sed -i '/#UseDNS yes/a UseDNS no' /etc/ssh/sshd_config
sed -i '/#PubkeyAuthentication yes/s/^#//' /etc/ssh/sshd_config

sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak@$currentTime

sudo cat > /etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
EOF


touch /etc/sudoers.d/nopasswd4sudo
echo "ubuntu ALL=(ALL) NOPASSWD : ALL"  >> /etc/sudoers.d/nopasswd4sudo


##network_config
NIC_CONF="/etc/netplan/01-netcfg.yaml"
NIC_NAME="ens32"

HOST_NAME="vhost"
NIC_IP="192.168.127.20"
GATWAY="192.168.127.254"
DNS1="114.114.114.114"
DNS2="8.8.8.8"
SUBNET="24"

mv $NIC_CONF $NIC_CONF'.bak@'$currentTime

cat > $NIC_CONF <<EOF
network:
    ethernets:
        ens32:
            addresses:
            - $NIC_IP/$SUBNET
            dhcp4: false
            dhcp6: false
            gateway4: $GATWAY
            nameservers:
                addresses:
                - $DNS1
                - $DNS2
                search: []
    version: 2
EOF

mv /etc/hosts /etc/host.bak@$currentTime
cat > /etc/hosts << EOF
# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

127.0.0.1       localhost
EOF

echo "$NIC_IP      $HOST_NAME " >> /etc/hosts
hostnamectl set-hostname $HOST_NAME

# netplan apply

# apt-get update
# apt-get upgrade
# apt-get install build-essential

posted @ 2018-10-23 00:04  javaite  阅读(1090)  评论(0编辑  收藏  举报