ArchLinux – 網路設定

原本的 ArchLinux 是使用 DHCP 自動取得 IP 連線,但要當成可以正式連線的 Server,就要改成使用固定 IP。
原本的設定(dhcp)
# vim /etc/netctl/eth0
Description=’A basic dhcp ethernet connection’
Interface=eth0
Connection=ethernet
IP=dhcp
ExecUpPost=’/usr/bin/ntpd -gq || true’

## for DHCPv6
#IP6=dhcp
## for IPv6 autoconfiguration
#IP6=stateless[@more@]改成固定 IP
# vim /etc/netctl/eth0
Description=’A basic static ethernet connection’
Interface=eth0
Connection=ethernet
AutoWired=yes
IP=static
Address=(‘192.168.1.23/24’)
Gateway=’192.168.1.254′
DNS=(‘168.95.1.1’ ‘140.111.66.1’ ‘8.8.8.8’)

## For IPv6 autoconfiguration
#IP6=stateles
## For IPv6 static address configuration
#IP6=static
#Address6=(‘1234:5678:9abc:def::1/64’ ‘1234:3456::123/96’)
#Routes6=(‘abcd::1234’)
#Gateway6=’1234:0:123::abcd’

讓設定生效
# systemctl reboot

用指令設定
DHCP
# ip link set eth0 up
# dhcpcd eth0

Static
# link link set eth0 up
# ip addr add 192.168.1.105/24 dev eth0
# ip route add default via 192.168.1.254

# systemctl enable dhcpcd@interface_name.service
# systemctl enable dhcpcd@eth0.service

# cd /etc/netctl
# netctl enable eth0

另外一種方式
設定 Static IP
# systemctl disable dhcpcd
# vim /etc/systemd/network/eth0.network
[Match]
Name=eth0

[Network]
DNS=168.95.1.1 140.111.66.1
Address=192.168.1.94/24
Gateway=192.168.1.254

設定 DHCP
# systemctl enable dhcpcd
# vim /etc/systemd/network/eth0.network
[Match]
Name=eth0

[Network]
DHCP=yes