forked from analogdevicesinc/linux_image_ADI-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enable_static_ip.sh
executable file
·40 lines (32 loc) · 1.12 KB
/
enable_static_ip.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
#!/bin/bash
#
# Enable a static IP for eth0 (or another interface) on Ubuntu-based setups.
# Note that the wanted IP address should be specified as the first argument;
# otherwise, it defaults to 192.168.0.101. Also, the interface can be specified
# as the second argument if the default (eth0) isn't wanted.
#
# Example usage:
# enable_static_ip.sh [10.66.99.101] [eth1]
#
# WARNING: Do not use this script if there is a custom network configuration
# set up in /etc/network/interfaces as it will be overwritten.
set -e
IP_ADDR=${1:-192.168.0.101}
ETH_DEV=${2:-eth0}
if [[ ${UID} -ne 0 ]]; then
echo "This script must be run as root!"
exit 1
fi
echo "Enabling the static IP address ${IP_ADDR} on ${ETH_DEV}"
# disable NetworkManager (assumes the config file hasn't been touched much)
sed -i 's/^managed=false/managed=true/' /etc/NetworkManager/NetworkManager.conf
# set up loopback and add static IP config for ${ETH_DEV} (defaults to eth0)
cat <<-EOF > /etc/network/interfaces
auto lo
iface lo inet loopback
auto ${ETH_DEV}
iface ${ETH_DEV} inet static
address ${IP_ADDR}
netmask 255.255.255.0
EOF
service network-manager restart