-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
61 lines (48 loc) · 1.17 KB
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# Ensure the script runs with root privileges
if [ "$(id -u)" -ne "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Bring up the ens3 interface
echo "Configuring network interface ens3..."
ip link set ens3 up
# Install dhclient if not already installed
echo "Installing dhclient..."
# Configure dhclient for ens3
echo "Creating dhclient service for ens3..."
cat <<EOF > /etc/systemd/system/dhclient.service
[Unit]
Description=Dynamic Host Configuration Protocol Client
After=network.target
[Service]
Type=simple
ExecStart=/sbin/dhclient -v ens3
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
# Restart dhclient service
echo "Starting dhclient for ens3..."
dhclient ens3
# Configure netplan
echo "Configuring netplan..."
cat <<EOF > /etc/netplan/01-netcfg.yaml
network:
version: 2
ethernets:
ens3:
dhcp4: yes
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
EOF
# Apply netplan configuration
echo "Applying netplan configuration..."
netplan apply
# Reinstall OpenSSH server
echo "Reinstalling OpenSSH server..."
apt-get install --reinstall -y openssh-server
echo "Setup completed."