Sebelisa ka botlalo sesebelisoa sa tsamaiso ea marang-rang ea NetworkManager moleng oa taelo oa Linux u sebelisa sesebelisoa sa nmcli.
Tšebeliso
E hlahile ka 2010 mme ho ba bangata e fetohile mokhoa o mong oa ho lokisa likhokahano tsa marang-rang le likhokahano. Le hoja batho ba bang ba ntse ba e sebelisa
ncmli taelo ea syntax
Ka kakaretso, syntax e shebahala tjena:
$ nmcli <options> <section> <action>
- likhetho ke liparamente tse khethollang bolotsana ba ts'ebetso ea nmcli,
- karolo (karolo) - e khetha hore na ke lisebelisoa life tse tla sebelisoa,
- ketso - e o lumella ho hlakisa hore na ke eng e hlileng e lokelang ho etsoa.
Ho na le likarolo tse 8 ka kakaretso, e 'ngoe le e' ngoe e amahanngoa le sehlopha se itseng sa litaelo (liketso):
- Thusa e fana ka thuso mabapi le litaelo tsa ncmcli le ts'ebeliso ea tsona.
- General e khutlisetsa boemo ba NetworkManager le tlhophiso ea lefats'e.
- Inthaneteng e kenyelletsa litaelo tsa ho botsa boemo ba khokahano ea marang-rang le ho nolofalletsa/ho tima likhokahano.
- seea-le- e kenyelletsa litaelo tsa ho botsa boemo ba khokahano ea marang-rang ea WiFi le ho nolofalletsa/ho tima likhokahano.
- ho hlokomela e kenyelletsa litaelo tsa ho beha leihlo tšebetso ea NetworkManager le ho bona liphetoho maemong a likhokahano tsa marang-rang.
- Kamano e kenyelletsa litaelo tsa ho laola likhokahano tsa marang-rang, ho eketsa likhokahano tse ncha le ho hlakola tse teng.
- Sesebelisoa haholo-holo e sebelisetsoang ho fetola lisebelisoa tse amanang le lisebelisoa (joalo ka lebitso la sebopeho) kapa ho hokahanya lisebelisoa ho sebelisa khokahano e teng.
- Secret e ngolisa nmcli joalo ka NetworkManager "moemeli oa lekunutu" ea mamelang melaetsa ea lekunutu. Karolo ena ha e sebelisoe hangata, hobane nmcli e sebetsa ka tsela ena ka ho sa feleng ha e hokela marang-rang.
Mehlala e bonolo
Pele o qala, etsa bonnete ba hore NetworkManager e sebetsa mme nmcli e ka buisana le eona:
$ nmcli general
STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN
connected full enabled enabled enabled enabled
Hangata mosebetsi o qala ka ho sheba li-profiles tsohle tsa khokahano ea marang-rang:
$ nmcli connection show
NAME UUID TYPE DEVICE
Wired connection 1 ac3241e4-b424-35d6-aaa7-07498561688d ethernet enp0s3
Wired connection 2 2279d917-fa02-390c-8603-3083ec5a1d3e ethernet enp0s8
Wired connection 3 52d89737-de92-35ec-b082-8cf2e5ac36e6 ethernet enp0s9
Taelo ena e sebelisa ketso bontša bakeng sa karolo ea Khokahano.
Mochini oa liteko o sebetsa Ubuntu 20.04. Tabeng ena, re fumane likhokahano tse tharo tsa marang-rang: enp0s3, enp0s8, le enp0s9.
Laola likhokahano
Ho bohlokoa ho utloisisa hore ho nmcli, ka lentsoe Connection re bolela setheo se nang le tlhaiso-leseling eohle mabapi le khokahano. Ka mantsoe a mang, sena ke tlhophiso ea marang-rang. Khokahano e akaretsa lintlha tsohle tse amanang le khokahano, ho kenyeletsoa lera la lihokelo le tlhaiso-leseling ea aterese ea IP. Tsena ke Layer 2 le Layer 3 mofuteng oa marang-rang oa OSI.
Ha u theha marang-rang ho Linux, hangata u theha likhokahano tse tla qetella li tlameletsoe ho lisebelisoa tsa marang-rang, tseo hape e leng li-interfaces tsa marang-rang tse kentsoeng khomphuteng. Ha sesebelisoa se sebelisa khokahano, se nkuoa se sebetsa kapa se phahame. Haeba khokahano e sa sebetse, ha e sebetse kapa e seta bocha.
Ho eketsa likhokahano tsa marang-rang
Ts'ebeliso ea ncmli e u lumella ho eketsa kapele le ho lokisa likhokahano hang-hang. Mohlala, ho eketsa khokahano ea Wired 2 (ka enp0s8), o hloka ho tsamaisa taelo e latelang joalo ka superuser:
$ sudo nmcli connection add type ethernet ifname enp0s8
Connection 'ethernet-enp0s8' (09d26960-25a0-440f-8b20-c684d7adc2f5) successfully added.
Khethong ea mofuta re bonts'a hore ena e tla ba khokahano ea Ethernet, 'me ho khetho ea ifname (interface name) re bonts'a sebopeho sa marang-rang seo re batlang ho se sebelisa.
Sena ke se tla etsahala ka mor'a ho tsamaisa taelo:
$ nmcli connection show
NAME UUID TYPE DEVICE
Wired connection 1 ac3241e4-b424-35d6-aaa7-07498561688d ethernet enp0s3
Wired connection 2 2279d917-fa02-390c-8603-3083ec5a1d3e ethernet enp0s8
Wired connection 3 52d89737-de92-35ec-b082-8cf2e5ac36e6 ethernet enp0s9
ethernet-enp0s8 09d26960-25a0-440f-8b20-c684d7adc2f5 ethernet --
Khokahano e ncha e entsoe, ethernet-enp0s8. E ne e abetsoe UUID mme mofuta oa khokahano e ne e le Ethernet. Ha re e phahamise re sebelisa up command:
$ nmcli connection up ethernet-enp0s8
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
Ha re hlahlobeng lenane la likhokahano tse sebetsang hape:
$ nmcli connection show --active
NAME UUID TYPE DEVICE
Wired connection 1 ac3241e4-b424-35d6-aaa7-07498561688d ethernet enp0s3
ethernet-enp0s8 09d26960-25a0-440f-8b20-c684d7adc2f5 ethernet enp0s8
Wired connection 3 52d89737-de92-35ec-b082-8cf2e5ac36e6 ethernet enp0s9
Khokahano e ncha ea ethernet-enp0s8 e kentsoe, e sebetsa ebile e sebelisa sebopeho sa marang-rang sa enp0s8.
Ho theha likhokahano
Ts'ebeliso ea ncmli e u lumella ho fetola habonolo liparamente tsa likhokahano tse teng. Ka mohlala, o hloka ho fetola aterese ea hau ea IP e matla (DHCP) ho aterese ea IP e tsitsitseng.
Ha re re re hloka ho beha aterese ea IP ho 192.168.4.26. Ho etsa sena re sebelisa litaelo tse peli. Ea pele e tla beha aterese ea IP ka kotloloho, 'me ea bobeli e fetole mokhoa oa ho hlophisa aterese ea IP hore e sebetse:
$ nmcli connection modify ethernet-enp0s8 ipv4.address 192.168.4.26/24
$ nmcli connection modify ethernet-enp0s8 ipv4.method manual
U se ke ua lebala ho beha le subnet mask. Bakeng sa khokahanyo ea rona ea liteko sena ke 255.255.255.0, kapa ka /24 bakeng sa tsela e se nang sehlopha (CIDR).
Hore liphetoho li tle li sebetse, o hloka ho koala, ebe o bula khokahano hape:
$ nmcli connection down ethernet-enp0s8
Connection 'ethernet-enp0s8' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
$ nmcli connection up ethernet-enp0s8
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveC
Haeba, ho fapana le hoo, o hloka ho kenya DHCP, sebelisa auto ho fapana le bukana:
$ nmcli connection modify ethernet-enp0s8 ipv4.method auto
Ho sebetsa le lisebelisoa
Bakeng sa sena re sebelisa karolo ea Sesebelisoa.
E hlahloba boemo ba sesebelisoa
$ nmcli device status
DEVICE TYPE STATE CONNECTION
enp0s3 ethernet connected Wired connection 1
enp0s8 ethernet connected ethernet-enp0s8
enp0s9 ethernet connected Wired connection 3
lo loopback unmanaged --
E kopa lintlha tsa sesebelisoa
Ho etsa sena, sebelisa ketso ea pontšo ho tloha karolong ea Sesebelisoa (o tlameha ho bolela lebitso la sesebelisoa). Sesebelisoa se bonts'a tlhahisoleseling e ngata, hangata maqepheng a 'maloa.
Ha re shebeng sebopeho sa enp0s8 seo khokahano ea rona e ncha e se sebelisang. Ha re etse bonnete ba hore e sebelisa aterese ea IP hantle eo re e behileng pejana:
$ nmcli device show enp0s8
GENERAL.DEVICE: enp0s8
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 08:00:27:81:16:20
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: ethernet-enp0s8
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/6
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 192.168.4.26/24
IP4.GATEWAY: --
IP4.ROUTE[1]: dst = 192.168.4.0/24, nh = 0.0.0.0, mt = 103
IP6.ADDRESS[1]: fe80::6d70:90de:cb83:4491/64
IP6.GATEWAY: --
IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 103
IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255
Ho na le litaba tse ngata haholo. Ha re totobatse ntho ea mantlha:
- Lebitso la marang-rang: enp0s8.
- Mofuta oa khokahano: khokahanyo ea Ethernet ea wired.
- Re bona aterese ea MAC ea sesebelisoa.
- Tekanyo e kholo ea phetisetso (MTU) e hlalositsoe - boholo bo boholo ba "data block" ea pakete e le 'ngoe e ka fetisoang ke protocol ntle le ho arohana.
- Sesebelisoa e hokahaneng hajoale.
- Lebitso la khokahanosesebelisoa se sebelisang: ethernet-enp0s8.
- Sesebelisoa se sebelisa Aterese ea IP, eo re e kentseng pejana: 192.168.4.26/24.
Lintlha tse ling li amana le mekhoa ea kamehla ea litsela le li-gateway tsa khokahanyo. Li itšetlehile ka marang-rang a khethehileng.
Interactive nmcli editor
nmcli e boetse e na le sebali se bonolo se sebetsanang, se ka bang bonolo hore ba bang ba sebetse le sona. Ho e tsamaisa khokahanong ea ethernet-enp0s8 mohlala, sebelisa ketso edit:
$ nmcli connection edit ethernet-enp0s8
E boetse e na le thuso e nyane, eo, leha ho le joalo, e nyane ka boholo ho feta mofuta oa console:
===| nmcli interactive connection editor |===
Editing existing '802-3-ethernet' connection: 'ethernet-enp0s8'
Type 'help' or '?' for available commands.
Type 'print' to show all the connection properties.
Type 'describe [<setting>.<prop>]' for detailed property description.
You may edit the following settings: connection, 802-3-ethernet (ethernet), 802-1x, dcb, sriov, ethtool, match, ipv4, ipv6, tc, proxy
nmcli>
Haeba o thaepa taelo ea khatiso ebe o tobetsa Enter, nmcli e tla bonts'a lisebelisoa tsohle tsa khokahano:
===============================================================================
Connection profile details (ethernet-enp0s8)
===============================================================================
connection.id: ethernet-enp0s8
connection.uuid: 09d26960-25a0-440f-8b20-c684d7adc2f5
connection.stable-id: --
connection.type: 802-3-ethernet
connection.interface-name: enp0s8
connection.autoconnect: yes
connection.autoconnect-priority: 0
connection.autoconnect-retries: -1 (default)
connection.multi-connect: 0 (default)
connection.auth-retries: -1
connection.timestamp: 1593967212
connection.read-only: no
connection.permissions: --
connection.zone: --
connection.master: --
connection.slave-type: --
connection.autoconnect-slaves: -1 (default)
connection.secondaries: --
Mohlala, ho seta khokahano ho DHCP, thaepa goto ipv4 ebe o tobetsa kena:
nmcli> goto ipv4
You may edit the following properties: method, dns, dns-search,
dns-options, dns-priority, addresses, gateway, routes, route-metric,
route-table, routing-rules, ignore-auto-routes, ignore-auto-dns,
dhcp-client-id, dhcp-iaid, dhcp-timeout, dhcp-send-hostname,
dhcp-hostname, dhcp-fqdn, dhcp-hostname-flags, never-default, may-fail,
dad-timeout
nmcli ipv4>
Ebe u ngola mokhoa oa ho seta auto ebe o tobetsa kena:
nmcli ipv4> set method auto
Do you also want to clear 'ipv4.addresses'? [yes]:
Haeba u batla ho hlakola aterese ea IP e sa fetoheng, tobetsa kena. Ho seng joalo, thaepa no ebe o tobetsa Enter. U ka e boloka haeba u nahana hore u tla e hloka nakong e tlang. Empa leha ho na le aterese ea IP e tsitsitseng, DHCP e tla sebelisoa haeba mokhoa o behiloe ho auto.
Sebelisa taelo ea ho boloka ho boloka liphetoho tsa hau:
nmcli ipv4> save
Connection 'ethernet-enp0s8' (09d26960-25a0-440f-8b20-c684d7adc2f5) successfully updated.
nmcli ipv4>
Tlanya ho tlohela ho tsoa ho nmcli Interactive Editor. Haeba u fetola maikutlo a hau mabapi le ho tsamaea, sebelisa taelo ea morao.
Mme ha se phetho
Bula nmcli Interactive Editor 'me u bone hore na ho na le li-setting tse kae le hore na sebaka ka seng se na le thepa e kae. Sehlophisi se sebetsanang ke sesebelisoa se setle, empa haeba u batla ho sebelisa nmcli ho li-line kapa lingoloa, u tla hloka mofuta o tloaelehileng oa mola oa taelo.
Kaha joale u na le lintlha tsa motheo, hlahloba
E le papatso
Li-server tsa Epic - sena ke
Source: www.habr.com