Setting an IP in Linux - CraigDonkin/Infrastructure GitHub Wiki

Setting an IP in Linux

replace [] with a value

[ip]/24 = 192.168.1.1/24

ifconfig


ifconfig eth[x] [ipaddress] netmaks [netmask] up
route add default gw [default gw]
echo "nameserver [DNS]" > /etc/resolv.conf
ifup eth[x]
ifdown eth[x]

ip

ip addr show
ip addr add [ip]/24 dev eth[x]
ip route add default via [ip] dev eth[x]
ip addr del [ip]/24 dev eth[x]
ip link set eth[x] up
ip link set eth[x] down
ip route add [ip]/24 via [ip] dev eth[x]

Persistent Static Routes

#RHEL
/etc/sysconfig/network-scripts/route-eth[x]
[ip]/24 via [ip] dev eth[x]

#Ubuntu/Deb/Mint
/etc/network/interfaces
auto eth[x]
iface eth[x] inet static
address [ip]
netmask [netmask]
gateway [gateway IP]
up ip route add [ip]/24 via [ip] dev eth[x]

VLANs

vconfig add eth[x] [vlanid]
ifconfig eth[x].[vlanid]
ifconfig eth[x].[vlanid] [ip] netmask [netmask] broadcast

#with IP

ip link add link eth[x] name eth[x].[vlanid] type vlan id [vlanid]
ip link
ip -d link show [interface just created]
ip addr add [ip]/24 brd [ip] dev [interface]
ip link set dev [interface] up

#to make it static
/etc/network/interfaces
auto eth[x].[vlanid]
iface [interface] inet static
	address [ip address]
	netmask [netmask]
	vlan-raw-device eth[x]
⚠️ **GitHub.com Fallback** ⚠️