-
Notifications
You must be signed in to change notification settings - Fork 0
/
ip.sh
31 lines (26 loc) · 896 Bytes
/
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
#!/bin/bash
#
## Tech and Me ## - ©2016, https://www.techandme.se/
#
IFCONFIG="/sbin/ifconfig"
IP="/sbin/ip"
IFACE=$($IP -o link show | awk '{print $2,$9}' | grep "UP" | cut -d ":" -f 1)
IFCONFIG="/sbin/ifconfig"
IP="/sbin/ip"
INTERFACES="/etc/network/interfaces"
ADDRESS=$($IFCONFIG $IFACE | awk -F'[: ]+' '/\<inet\>/ {print $4; exit}')
NETMASK=$($IFCONFIG $IFACE | awk -F'[: ]+' '/\<inet\>/ {print $8; exit}')
GATEWAY=$($IP route | awk '/\<default\>/ {print $3; exit}')
cat <<-IPCONFIG > "$INTERFACES"
auto lo $IFACE
iface lo inet loopback
iface $IFACE inet static
address $ADDRESS
netmask $NETMASK
gateway $GATEWAY
pre-up /sbin/ethtool -K $IFACE tso off
pre-up /sbin/ethtool -K $IFACE gso off
# Exit and save: [CTRL+X] + [Y] + [ENTER]
# Exit without saving: [CTRL+X]
IPCONFIG
exit 0