Setup Ethernet LAN Arch Linux


Để setup ip cho card mạng có dây, ta dùng gói netctl. Nếu các bạn chưa cài thì có thể cài bằng câu lệnh sau.

sudo pacman -S netctl dhcpcd

Lưu ý là nếu các bạn có cài NetworkManager thì phải stop và disable nó đi không là sẽ bị conflict.

systemctl stop NetworkManager.service
systemctl disable  NetworkManager.service

Sau đó ta copy file cấu hình trong examples vào /etc/netctl.

cd /etc/netctl/examples
cp ethernet-dhcp ../ethernet

Sau khi chép xong ta có profile ethernet. Tên này ta muốn đặt gì cũng được nhé.

% cd /etc/netctl   

/etc/netctl
% ls
ethernet  examples  hooks  interfaces  wifi_vnpt

/etc/netctl
% cat ethernet     
Description='A basic dhcp ethernet connection'
Interface=enp0s20u2u2 # tên card mạng , dùng lệnh 'ip address' sẽ thấy.
Connection=ethernet
IP=dhcp

/etc/netctl
% 

Bậy giờ ta sẽ start profile ethernet bằng câu lênh.

sudo netctl start ethernet 

Còn muốn tự động start profile ethernet khi khởi động máy ta dùng câu lệnh sau.

sudo netctl enable ethernet

Xem status của profile

[dt@dt-arco netctl]$ netctl status ethernet
● netctl@ethernet.service - A basic dhcp ethernet connection
     Loaded: loaded (/usr/lib/systemd/system/netctl@.service; enabled; vendor preset: disabled)
    Drop-In: /etc/systemd/system/netctl@ethernet.service.d
             └─profile.conf
     Active: active (running) since Sun 2021-08-22 07:56:43 +07; 2s ago
       Docs: man:netctl.profile(5)
   Main PID: 2072 (network)
      Tasks: 7 (limit: 9421)
     Memory: 2.8M
        CPU: 68ms
     CGroup: /system.slice/system-netctl.slice/netctl@ethernet.service
             ├─2072 /bin/bash /usr/lib/netctl/network start ethernet
             ├─2107 "dhcpcd: [launcher]" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2109 "dhcpcd: enp0s20u2u2 [ip4]" "" "" "" "" "" "" "" ""
             ├─2110 "dhcpcd: [privileged actioneer] enp0s20u2u2 [ip4]"
             ├─2111 "dhcpcd: [control proxy] enp0s20u2u2 [ip4]"
             ├─2114 "dhcpcd: [BPF BOOTP] enp0s20u2u2" "" ""
             └─2115 "dhcpcd: [BPF ARP] enp0s20u2u2 192.168.1.14"

Thg 8 22 07:56:40 dt-arco systemd[1]: Starting A basic dhcp ethernet connection...
Thg 8 22 07:56:40 dt-arco network[2072]: Starting network profile 'ethernet'...
Thg 8 22 07:56:43 dt-arco systemd[1]: Started A basic dhcp ethernet connection.
Thg 8 22 07:56:43 dt-arco dhcpcd[2107]: dhcpcd-9.4.0 starting
Thg 8 22 07:56:43 dt-arco dhcpcd[2110]: DUID 00:04:f6:f0:c8:85:66:da:15:51:9d:04:d1:b1:ce:9a:93:09
Thg 8 22 07:56:43 dt-arco dhcpcd[2110]: enp0s20u2u2: IAID c6:c0:e1:2f
Thg 8 22 07:56:44 dt-arco dhcpcd[2110]: enp0s20u2u2: soliciting a DHCP lease
Thg 8 22 07:56:45 dt-arco dhcpcd[2110]: enp0s20u2u2: offered 192.168.1.14 from 192.168.1.1
Thg 8 22 07:56:45 dt-arco dhcpcd[2110]: enp0s20u2u2: probing address 192.168.1.14/24
[dt@dt-arco netctl]$

Ta xem ip của card LAN nào.

% ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
5: enp0s20u2u2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0e:c6:c0:e1:2f brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.14/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s20u2u2
       valid_lft 86109sec preferred_lft 75309sec
    inet6 2001:ee0:56b4:dc70:20e:c6ff:fec0:e12f/64 scope global dynamic mngtmpaddr 
       valid_lft 905sec preferred_lft 905sec
    inet6 fe80::20e:c6ff:fec0:e12f/64 scope link 
       valid_lft forever preferred_lft forever

/etc/netctl
% 

Như vậy là card LAN của chúng ta đã có ip là 192.168.1.14/24. Enjoy ^_^