Pavel Mikula
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Test A VM, který má nastavené: - Karta 1 - NAT - Karta 2 - Síť pouze s hostem -> bez DHCP ## Pro přehlednost <small>optional</small> ``` hostname master ``` ## Nastavení sítě Do souboru `/etc/network/interfaces` přidám ```bash # The loopback network interface auto lo iface lo inet loopback # Karta 1 - NAT auto enp0s3 iface enp0s3 inet dhcp # Karta 2 - Host auto enp0s8 iface enp0s8 inet static address 192.168.68.10 netmask 255.255.255.0 ``` Restartujeme -> `service networking restart` ## Dependencies ``` apt update apt install isc-dhcp-server ``` > Pri startu schválně spadne. :-) ## Postup Nastavim interface DHCP serveru `/etc/default/isc-dhcp-server` ``` INTERFACESv4="enp0s8" INTERFACESv6="" ``` `sed -i 's/INTERFACESv4=""/INTERFACESv4="enp0s8"/' /etc/default/isc-dhcp-server` Upravím config v `/etc/dhcp/dhcpd.conf` ``` option domain-name "vsb.cz"; option domain-name-servers 158.196.0.53; -- školní DNS, jina nepůjde, security # Pro test doma #option domain-name "google.cz"; #option domain-name-servers 8.8.8.8; subnet 192.168.68.0 netmask 255.255.255.0 { range 192.168.68.100 192.168.68.200; option routers 192.168.68.10; } ``` > [!Note] > Authoritative znamená, že dhcp server nastaví adresu i pro requesty z jiných sítí -- by default by musel být jeden DHCP server na jeden subnet - request na L2 neprojde routerem. To se zase řeší na routerech pomocí `iphelper`, který přes L3 pošle ten request přímo na DHCP server -- stačí 1 server na síti > > Na síti nechceme mít více DHCP serverů, dělalo by to bordel. Switche umí `dhcp snooping` -- port směrem k DHCP serveru se nastaví jako trusted a příchozí requesty se přepošlou jen tam, takže i kdybych si připojil druhý na jiný port, tak to ničemu nebude vadit. Restartuju server `service isc-dhcp-server restart` `dhcpd -t` -- *kontrola konfigurace, zda je správná* `cat /var/lib/dhcp/dhcpd.leases` -- *list půjčených ip address* ## Testovácí PC Vytvořím si testovací VM, kterému dám stejnou kartu s "vypnutým" DHCP. Defakto je ale DHCP zapnuté a to naše. Po zapnutí by měl PC dostat ip addresu. **Může to chvíli trvat** -> případně `dhclient enp0s8` Následně vyzkouším třeba `ping 192.168.68.10` ## Nastavení NAT (maškaráda) Musím povolit IP forward (přeposílání packetu mezi interfacy). Bez toho si nebudou povídat mezi sítěmi. Do souboru v `/etc/sysctl.d/ip_forward.conf` vložím `net.ipv4.ip_forward = 1` Načtu config pomocí `sysctl -p /etc/sysctl.d/ip_forward.conf` `cat /proc/sys/net/ipv4/ip_forward` -- *zjištění, zda ip forward běží* -> expected: 1 `sysctl --all | grep ip_forward` -- *konfigurace, bez grep všechny* Povolím NAT pomocí: ```bash nft add table nat nft add chain nat postrouting { type nat hook postrouting priority 100 \; } nft add rule nat postrouting masquerade ``` Uložíme config, aby i po restartu bězel `nft list ruleset >> /etc/nftables.conf` Povolíme firewall, aby fungovala nat `systemctl enable nftables` ## Instalace TFTP serveru Nainstaluju pomocí `apt install tftpd-hpa` Vytvořím si test soubor, pro oveření `echo "Hello, World" > /srv/tftp/file.txt` Na test PC `apt install tftp-hpa` a připojím se `tftp 192.168.68.10` Stáhnu test soubor `file.txt` z adresáře `/srv/tftp` pomocí `binary` a `get file.txt` Opustím pomocí `quit` ## Instalace netboot Stáhnu si netboot do `/srv/tftp` ``` wget http://ftp.debian.org/debian/dists/stable/main/installer-amd64/current/images/netboot/netboot.tar.gz tar -xvf netboot.tar.gz rm netboot.tar.gz ``` Upravím `/etc/dhcp/dhcpd.conf` ``` subnet 192.168.68.0 netmask 255.255.255.0 { range 192.168.68.100 192.168.68.200; option routers 192.168.68.10; # Nové option broadcast-address 192.168.68.255; next-server 192.168.68.10; filename "pxelinux.0"; } ``` Restartuju `service isc-dhcp-server restart` ## Vytvořím si nový virtual debian pc pro clienta - Musí být bez disku - System -> Boot order -> Pouze z networku - Network -> pouze jedna karta -> Host-only adapter -> vboxnet1 (bez DHCP) Po startu clienta, by se mi měla automaticky spustit instalačka Debianu ## Instalace NFS Server `apt install nfs-kernel-server` Vytvořím si adresář, kde bude klientský root `mkdir /srv/tftp/rootfs` a home `mkdir -p /srv/tftp/home` Vytvořím configurační soubor `/etc/exports`, přidám ``` /srv/tftp/rootfs 192.168.68.0/24(rw,async,no_root_squash) /srv/tftp/home 192.168.68.0/24(rw,async,no_root_squash) ``` > [!Note] > `async` -- dává se pro rychlost > `no_root_squash` -- normálně nemůžu mount jako root (uid 0), toto mi to dovolí Aktivuju `exportfs -ra` a restartuju server pomocí `service nfs-kernel-server restart` `exportfs` -- *kontrola konfigurace* -> expected: ``` /srv/tftp/rootfs 192.168.68.0/24 /srv/tftp/home 192.168.68.0/24 ``` Vytvořím fstab konfiguraci `/srv/tftp/rootfs/etc/fstab`, použiju ho proto, aby mi namountovala home a proc, až po inicializaci rootfs. ``` proc /proc proc defaults 0 0 192.168.68.10:/srv/tftp/home /home nfs defaults,_netdev 0 0 ``` > [!Note] > `_netdev` -- kritické pro konfiguraci, jelikož čeká až se inicializuji network ## Otestuju na test PC (NE! toho bez disku) Na test pc `apt install nfs-common` Mountnu disk `mount 192.168.68.10:/srv/tftp/rootfs /mnt` Zkusím vytvořit nějaký soubor a měl by se zobrazit v rootu `touch /mnt/test.txt` ## Root file system Jsem v `/srv/tftp/rootfs`, některé věci překopíruju, některé vytvořím nové ``` cp -r /bin . cp -r /boot . mkdir dev cp -r /etc . cp -r /lib . cp -r /lib64 . mkdir media mkdir mnt cp -r /opt . mkdir proc cp -r /root . mkdir run cp -r /sbin . mkdir srv mkdir sys mkdir tmp cp -r /usr . cp -r /var . chmod o+t tmp/ ``` Home directory existuje mimo rootfs -> `cp -r /home /srv/tftp/home` > `chmod o+t tmp/` -- nastaví složku jako temp -- každý může zapsat soubor, ale upravit může jen svůj, cizí ne ## BIND9 relay Nainstalujeme bind `apt install bind9`, aby fungoval jako "forwarder" pro naší NAT. Bude cachovat dotazy a případně se starat o naše klientské servery. Vytvořím konfigurace: */etc/bind/named.conf.options* ``` options { directory "/var/cache/bind"; recursion yes; allow-query { any; }; forwarders { 8.8.8.8; 1.1.1.1; }; dnssec-validation auto; listen-on { any; }; listen-on-v6 { any; }; }; ``` Restartuji pomocí `systemctl restart bind9` ## Linux soubory fucki-waki Odložím si aktuální konfigurace, jsem v `/srv/tftp` ```bash mkdir /srv/tftp/backup mv ldlinux.c32 backup/ mv pxelinux.0 backup/ mv pxelinux.cfg backup/ mv splash.png backup/ mv version.info backup/ ``` Poté to zase vrátím zpět, ale jen to co potřebuji, lol: ```bash cp debian-installer/amd64/boot-screens/libcom32.c32 . cp debian-installer/amd64/boot-screens/vesamenu.c32 . cp debian-installer/amd64/boot-screens/libutil.c32 . cp -r backup/ldlinux.c32 . cp -r backup/pxelinux.cfg . cp -r backup/pxelinux.0 . ``` Zkontroluji si pokud mám dobrou verzi v `/rootfs/boot` -> verze 6.12.57 Upravím `/srv/tftp/pxelinux.cfg/default` na ``` DEFAULT vesamenu.c32 PROMPT 0 MENU TITLE Boot Menu LABEL Debian - NetBoot MENU LABEL Start Network OS KERNEL /rootfs/boot/vmlinuz-6.12.57+deb13-amd64 APPEND initrd=/rootfs/boot/initrd.img-6.12.57+deb13-amd64 root=/dev/nfs nfsroot=192.168.68.10:/srv/tftp/rootfs ip=dhcp rw LABEL Debian - Install MENU LABEL Install Debian KERNEL debian-installer/amd64/linux APPEND initrd=debian-installer/amd64/initrd.gz ip=dhcp ``` Jelikož jsme kopírovali ze serveru na klienta, musím upravit: 1. Klient hledá disk přiřazený serveru, ale klient žádný nemá, zakomentuju vše v `/srv/tftp/rootfs/etc/fstab` kromě toho co jsem přidal 2. Server měl 2 sítovky, ale klient má jen jednu, takže v `/srv/tftp/rootfs/etc/network/interfaces` zakomentuju vše kromě loopbacku (lo) 3. Smažu nepotřebné servisy z klienta `apt remove isc-dhcp-server nfs-kernel-server tftpd-hpa` > [!Important] > Proč by byl problém, kdybychom chtěli mít více klientů zároveň? > - Kolize v `/tmp` -- na jednom pc si zapneme Mozillu, ta si tam udělá temp. soubory. Když zkusíme zapnout i na druhém, pošle nás do hajzlu, že už vlastně běží > - Logy -- jednotlivé PC se nijak neidentifikují --> hrozný bordel (kromě toho, že bude hodně zapisování do toho jednoho souboru ze všech PC) > > Řešení -- logovat můžeme na vzdálený PC, `/tmp` namountíme do paměti klienta (ale musíme počítat s tím, že se tmp neukládá) > Další výhody / nevýhody? Co udělám na jednom pc, stane se na všech (`Super, stáhl jsem package jednou a mají ho všichni`, ale `Kurva, posral jsem config, rozbil jsem to všem`)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully