Dokument ten opisuje sposób instalacji jądra 3.1.9 i iptables z IMQ oraz SQUIDa, gdy mamy NAT. Opisane poniżej czynności wykonałem w dystrybucji Slackware 13.37. W chwili gdy piszę te słowa (18 stycznia 2012) istnieją następujące wersje programów:
* Jądro 3.1.9 - nowsze do ściągnięcia z www.kernel.org . Wprawdzie pojawiły się parę dni temu jądra serii 3.2 ale ponieważ nie ma do nich na razie patcha IMQ to nie będę ich tutaj stosować.
* Patch IMQ do jądra serii 3.1
* iptables 1.4.12.2 - nowsze do ściągnięcia z www.iptables.org
* Squid 3.2.0.14 - nowsze do ściągnięcia z www.squid-cache.org . Wprawdzie wersja 3.2 posiada status beta ale dopiero od tej wersji mozliwe jest stosowanie tcp_outgoing_mark

Konwencje użyte w tym dokumencie:

Opis poszczególnych czynności oznaczam drukiem wytłuszczonym i są one numerowane

+ Polecenia wydawane przez użytkownika oznaczam podkreśleniem. Tego plusa na początku każdej linii oczywiście nie wpisujesz.

Moje komentarze wewnątrz poszczególnych punktów są pisane kursywą

Wyniki działania poszczególnych poleceń jest pisana właśnie tak.
(...) oznacza, że tych wyników jest bardzo dużo i wtedy zamieszczam zazwyczaj 3 pierwsze i 3 ostatnie linijki a resztę zastępuje przez (...)



  1. Przechodzisz do katalogu /usr/src
    + cd /usr/src/

  2. Ściągasz aktualny kernel
    + wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.1.9.tar.bz2

    Powinieneś otrzymać:
    --2012-01-17 18:55:53-- http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.1.9.tar.bz2
    Resolving www.kernel.org (www.kernel.org)... 149.20.4.69
    Connecting to www.kernel.org (www.kernel.org)|149.20.4.69|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 77249793 (74M) [application/x-bzip2]
    Saving to: "linux-3.1.9.tar.bz2"

    0K .......... .......... .......... .......... .......... 0% 74.0K 16m59s
    50K .......... .......... .......... .......... .......... 0% 210K 11m29s
    100K .......... .......... .......... .......... .......... 0% 769K 8m11s
    (...)
    75300K .......... .......... .......... .......... .......... 99% 4.41M 0s
    75350K .......... .......... .......... .......... .......... 99% 236K 0s
    75400K .......... .......... .......... ......... 100% 190K=3m8s

    2012-01-17 18:59:02 (402 KB/s) - "linux-3.1.9.tar.bz2" saved [77249793/77249793]

  3. Rozpakowujesz kernel
    + tar xfj linux-3.1.9.tar.bz2
    Powinieneś otrzymac katalog /usr/src/linux-3.1.9 a w nim rozpakowane źródła kernela

  4. Usuwasz katalog /usr/src/linux (o ile takowy istnieje)
    + rm /usr/src/linux

  5. Tworzysz linka symbolicznego katalogu /usr/src/linux do katalogi /usr/src/linux-3.1.9
    + ln -s /usr/src/linux-3.1.9 /usr/src/linux

  6. Ściągasz aktualny iptables
    + wget http://www.netfilter.org/projects/iptables/files/iptables-1.4.12.2.tar.bz2

    Powinieneś otrzymać:
    --2012-01-17 18:59:56-- http://www.netfilter.org/projects/iptables/files/iptables-1.4.12.2.tar.bz2
    Resolving www.netfilter.org (www.netfilter.org)... 213.95.27.115, 2001:780:45:1d:20d:93ff:fe9b:e443
    Connecting to www.netfilter.org (www.netfilter.org)|213.95.27.115|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 480861 (470K) [application/x-bzip2]
    Saving to: "iptables-1.4.12.2.tar.bz2"

    0K .......... .......... .......... .......... .......... 10% 207K 2s
    50K .......... .......... .......... .......... .......... 21% 310K 1s
    100K .......... .......... .......... .......... .......... 31% 767K 1s
    150K .......... .......... .......... .......... .......... 42% 236K 1s
    200K .......... .......... .......... .......... .......... 53% 741K 1s
    250K .......... .......... .......... .......... .......... 63% 769K 0s
    300K .......... .......... .......... .......... .......... 74% 735K 0s
    350K .......... .......... .......... .......... .......... 85% 765K 0s
    400K .......... .......... .......... .......... .......... 95% 739K 0s
    450K .......... ......... 100% 776K=1.0s

    2012-01-17 18:59:57 (452 KB/s) - "iptables-1.4.12.2.tar.bz2" saved [480861/480861]

  7. Rozpakowujesz iptables
    bzip2 -dc iptables-1.4.12.2.tar.bz2 | tar xf -
    Powinieneś otrzymac katalog /usr/src/iptables-1.4.12.2 a w nim rozpakowane źródła iptables

  8. Przechodzisz do katalogu /usr/src/linux
    + cd /usr/src/linux

  9. Ściągasz patch IMQ do kernela 3.1.x
    + wget http://www.linuximq.net/patchs/patch-imqmq-3.1.diff.bz2
    Powinieneś otrzymać:
    --2012-01-17 18:59:58-- http://www.linuximq.net/patchs/patch-imqmq-3.1.diff.bz2
    Resolving www.linuximq.net (www.linuximq.net)... 89.38.58.162
    Connecting to www.linuximq.net (www.linuximq.net)|89.38.58.162|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 12257 (12K) [application/x-bzip2]
    Saving to: "patch-imqmq-3.1.diff.bz2"

    0K .......... . 100% 139K=0.09s

    2012-01-17 18:59:59 (139 KB/s) - "patch-imqmq-3.1.diff.bz2" saved [12257/12257]

  10. Patchujesz kernel
    + bzip2 -dc patch-imqmq-3.1.diff.bz2 | patch -p1
    Powinieneś otrzymać:
    patching file drivers/net/imq.c
    patching file drivers/net/Kconfig
    patching file drivers/net/Makefile
    patching file include/linux/imq.h
    patching file include/linux/netfilter/xt_IMQ.h
    patching file include/linux/netfilter.h
    patching file include/linux/netfilter_ipv4/ipt_IMQ.h
    patching file include/linux/netfilter_ipv6/ip6t_IMQ.h
    patching file include/linux/skbuff.h
    Hunk #6 succeeded at 2181 (offset 5 lines).
    patching file include/net/netfilter/nf_queue.h
    patching file net/core/dev.c
    patching file net/core/skbuff.c
    patching file net/ipv6/ip6_output.c
    patching file net/netfilter/core.c
    patching file net/netfilter/Kconfig
    patching file net/netfilter/Makefile
    patching file net/netfilter/nf_internals.h
    patching file net/netfilter/nf_queue.c
    patching file net/netfilter/xt_IMQ.c

  11. Uzyskujesz plik .config zawierający konfigurację Twojego aktualnego kernela
    + zcat /proc/config.gz >.config

  12. Dopisujesz do pliku .config opcje związane z nowym kernelem
    + make oldnoconfig

    Powinieneś otrzymać:
    HOSTCC scripts/basic/fixdep
    HOSTCC scripts/kconfig/conf.o
    SHIPPED scripts/kconfig/zconf.tab.c
    SHIPPED scripts/kconfig/zconf.lex.c
    SHIPPED scripts/kconfig/zconf.hash.c
    HOSTCC scripts/kconfig/zconf.tab.o
    HOSTLD scripts/kconfig/conf
    scripts/kconfig/conf --oldnoconfig Kconfig
    .config:473:warning: symbol value 'm' invalid for ACPI_APEI_GHES
    .config:1152:warning: symbol value 'm' invalid for BT_L2CAP
    .config:1153:warning: symbol value 'm' invalid for BT_SCO
    .config:4073:warning: symbol value 'm' invalid for HID_ACRUX_FF
    .config:4422:warning: symbol value 'm' invalid for RTC_LIB
    .config:4423:warning: symbol value 'm' invalid for RTC_CLASS
    #
    # configuration written to .config
    #


  13. Włączasz w konfiguracji kernela opcje związane z IMQ
    + sed -i 's/# CONFIG_NETFILTER_XT_TARGET_IMQ is not set/CONFIG_NETFILTER_XT_TARGET_IMQ=m/' .config
    + sed -i 's/# CONFIG_IMQ is not set/CONFIG_IMQ=m\n# CONFIG_IMQ_BEHAVIOR_AA is not set\nCONFIG_IMQ_BEHAVIOR_AB=y\n# CONFIG_IMQ_BEHAVIOR_BA is not set\n# CONFIG_IMQ_BEHAVIOR_BB is not set\nCONFIG_IMQ_NUM_DEVS=4\n/' .config

    Można to wprawdzie zrobić za pomocą make menuconfig ale wtedy musiałbyć przedzierać się przez gąszcz ustawień. Konkretnie musiałbyś włączyć następujące opcje:
    Networking support -> Networking options -> Network packet filtering framework (Netfilter) -> Core Netfilter Configuration -> IMQ target support -> M
    Device Drivers -> Network sevice support -> IMQ (intermediate queueing device) support -> M
    Tutaj wybrałem dla IMQ opcję AB oraz wybrałem maksymalnie 4 interfejsy IMQ. Domyślnie jest ich 16. Dla mnie wystarcza tylko 2 ale na wszelki wypadek ustawiam ich 4. Jeśli chcesz zmienić inne opcje w Twoim kernelu to tu jest właśnie meisce do wykonania

  14. Kompilujesz kernel
    + make all
    To może potrwać baaardzo długo. Powinieneś otrzymać:
    scripts/kconfig/conf --silentoldconfig Kconfig
    CHK include/linux/version.h
    UPD include/linux/version.h
    (...)
    IHEX firmware/sb16/ima_adpcm_init.csp
    IHEX firmware/sb16/ima_adpcm_playback.csp
    IHEX firmware/sb16/ima_adpcm_capture.csp


  15. Instalujesz skompilowane moduły
    + make modules_install
    Powinieneś otrzymać:
    INSTALL arch/x86/crypto/crc32c-intel.ko
    INSTALL arch/x86/crypto/salsa20-i586.ko
    INSTALL arch/x86/kernel/apm.ko
    (...)
    INSTALL /lib/firmware/sb16/ima_adpcm_playback.csp
    INSTALL /lib/firmware/sb16/ima_adpcm_capture.csp
    DEPMOD 3.1.9-smp

  16. Do zmiennej OLDKERNEL zapisujesz nazwę pliku zawierajacego Twoje aktualne jądro
    ++ OLDKERNEL=`ls -l /boot/vmlinuz | cut -d ' ' -f 11`

  17. W pliku /etc/lilo.conf zmieniasz nazwę jądra vmlinuz na prawdziwą
    + sed -i 's/image = \/boot\/vmlinuz$/image = \/boot\/$OLDKERNEL/' /etc/lilo.conf

  18. W pliku /etc/lilo.conf zmieniasz etykietę jądra Linux na Linux-old
    + sed -i 's/ label = Linux/ label = Linux-old/' /etc/lilo.conf

  19. Instalujemy nowy kernel
    + make install
    Powinienes otrzymać nowy kernel w katalogo /boot jako plik vmlinuz oraz następujące komunikaty:
    sh /usr/src/linux-3.1.9/arch/x86/boot/install.sh 3.1.9-smp arch/x86/boot/bzImage \
    System.map "/boot"
    Warning: LBA32 addressing assumed
    Added Linux-old *
    One warning was issued.

  20. Dostosowujemy nazwy plików vmlinuz, System.map i config zgodnie z tym opisem
    + cd /etc/rc.d
    + cp rc.modules rc.modules-3.1.9
    + rm rc.modules
    + ln -s /etc/rc.d/rc.modules-3.1.9 /etc/rc.d/rc.modules
    + mv /boot/vmlinuz /boot/vmlinuz-3.1.9
    + ln -s /boot/vmlinuz-3.1.9 /boot/vmlinuz
    + mv /boot/System.map /boot/System.map-3.1.9
    + ln -s /boot/System.map-3.1.9 /boot/System.map
    + cp /usr/src/linux/.config /boot/config-3.1.9
    + rm /boot/config
    + ln -s /boot/config-3.1.9 /boot/config


  21. Dopisujemy nowy kernel do /etc/lilo.conf
    + sed -i 's/# Linux bootable partition config begins/# Linux bootable partition config begins\nimage = \/boot\/vmlinuz-3.1.9\n root = \/dev\/sda1\n label = Linux-3.1.9\n read-only/' /etc/lilo.conf

  22. Uruchamiasz lilo
    + lilo
    Powinieneś otrzymać
    Warning: LBA32 addressing assumed
    Added Linux-3.1.9 *
    Added Linux-old
    One warning was issued.


  23. Przechodzisz do katalogu źródeł iptables
    + cd /usr/src/iptables-1.4.12.2

  24. Pobierasz patch IMQ do iptables
    + wget http://www.linuximq.net/patchs/iptables-1.4.12-IMQ-test4.diff
    Powinieneś otrzymać:
    --2012-01-17 20:39:27-- http://www.linuximq.net/patchs/iptables-1.4.12-IMQ-test4.diff
    Resolving www.linuximq.net (www.linuximq.net)... 89.38.58.162
    Connecting to www.linuximq.net (www.linuximq.net)|89.38.58.162|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 4310 (4.2K) [text/x-diff]
    Saving to: "iptables-1.4.12-IMQ-test4.diff"

    0K .... 100% 445K=0.009s

    2012-01-17 20:39:29 (445 KB/s) - "iptables-1.4.12-IMQ-test4.diff" saved [4310/4310]


  25. Patchujesz iptables dla IMQ
    + patch -p1 <iptables-1.4.12-IMQ-test4.diff
    Powinieneś otrzymać:
    patching file extensions/libxt_IMQ.c
    patching file extensions/libxt_IMQ.man
    patching file include/linux/netfilter/xt_IMQ.h


  26. Konfigurujesz iptables
    + ./configure
    Powinieneś otrzymać:
    checking for a BSD-compatible install... /usr/bin/ginstall -c
    checking whether build environment is sane... yes
    checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
    (...)
    config.status: creating config.h
    config.status: executing depfiles commands
    config.status: executing libtool commands

  27. Kompilujesz iptables
    + make
    Powinienes otrzymać:
    make all-recursive
    make[1]: Entering directory `/usr/src/iptables-1.4.12.2'
    Making all in libiptc
    (...)
    make[2]: Nothing to be done for `all-am'.
    make[2]: Leaving directory `/usr/src/iptables-1.4.12.2'
    make[1]: Leaving directory `/usr/src/iptables-1.4.12.2'

  28. Instalujesz iptables
    + make install
    Powinieneś otrzymać:
    Making install in libiptc
    make[1]: Entering directory `/usr/src/iptables-1.4.12.2/libiptc'
    make[2]: Entering directory `/usr/src/iptables-1.4.12.2/libiptc'
    {...)
    make[2]: Nothing to be done for `install-data-am'.
    make[2]: Leaving directory `/usr/src/iptables-1.4.12.2'
    make[1]: Leaving directory `/usr/src/iptables-1.4.12.2'

  29. Przechodzisz do katalogu /usr/src
    + cd /usr/src

  30. Ściągasz źródła Squida
    + wget http://www.squid-cache.org/Versions/v3/3.2/squid-3.2.0.14.tar.gz
    Powinieneś otrzymać:
    --2012-01-17 20:41:37-- http://www.squid-cache.org/Versions/v3/3.2/squid-3.2.0.14.tar.gz
    Resolving www.squid-cache.org (www.squid-cache.org)... 209.169.10.131, 198.186.193.234
    Connecting to www.squid-cache.org (www.squid-cache.org)|209.169.10.131|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 4059672 (3.9M) [application/x-gzip]
    Saving to: "squid-3.2.0.14.tar.gz"

    0K .......... .......... .......... .......... .......... 1% 78.6K 50s
    50K .......... .......... .......... .......... .......... 2% 253K 32s
    100K .......... .......... .......... .......... .......... 3% 296K 26s
    (...)
    3900K .......... .......... .......... .......... .......... 99% 732K 0s
    3950K .......... .... 100% 637K=9.6s

    2012-01-17 20:41:48 (413 KB/s) - "squid-3.2.0.14.tar.gz" saved [4059672/4059672]

  31. Rozpakowujesz źródła Squida
    + tar -zxf squid-3.2.0.14.tar.gz

  32. Przechodzisz do katalogu źródeł Squida
    + cd /usr/src/squid-3.2.0.14

  33. Konfigurujesz Squida
    + ./configure --enable-err-languages=Polish --enable-default-err-language=Polish --enable-underscores --enable-linux-netfilter --disable-carp --disable-wccp --disable-wccpv2 --disable-snmp --disable-htcp --disable-ident-lookups --disable-unlinkd --disable-translation --disable-auto-locale --disable-loadable-modules --disable-esi --disable-eui --enable-storeio=ufs --disable-auth-ntlm --disable-auth-negotiate --disable-auth-digest --disable-cache-digests --disable-ntlm-auth-helpers --disable-negotiate-auth-helpers --disable-digest-auth-helpers --disable-ipfw-transparent --disable-ipf-transparent --disable-pf-transparent --disable-linux-tproxy --disable-url-rewrite-helpers --disable-win32-service --disable-zph-qos --disable-icap-client --disable-ecap --disable-useragent-log --disable-referer-log --disable-eui --disable-poll --disable-select --disable-kqueue --disable-icmp --disable-gnuregex --disable-cpu-profiling --disable-kill-parent-hack --disable-follow-x-forwarded-for --disable-forw-via-db --without-valgrind-debug --without-ipv6-split-stack --without-po2html
    Powinieneś otrzymać:
    checking for a BSD-compatible install... /usr/bin/ginstall -c
    checking whether build environment is sane... yes
    checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
    (...)
    config.status: creating config.h
    config.status: executing depfiles commands
    config.status: executing libtool commands

  34. Kompilujesz Squida
    + make all
    Powinieneś otrzymać
    Making all in compat
    make[1]: Entering directory `/usr/src/squid-3.2.0.14/compat'
    g++ -DHAVE_CONFIG_H -I.. -I../include -I../lib -I../src -I../include -Wall -Wpointer-arith -Wwrite-strings -Wcomments -Werror -pipe -D_REENTRANT -g -O2 -MT assert.o -MD -MP -MF .deps/assert.Tpo -c -o assert.o assert.cc
    (...)
    make[1]: Entering directory `/usr/src/squid-3.2.0.14'
    make[1]: Nothing to be done for `all-am'.
    make[1]: Leaving directory `/usr/src/squid-3.2.0.14'

  35. Instalujesz Squida
    + make install
    Powinieneś otrzymać:
    Making install in compat
    make[1]: Entering directory `/usr/src/squid-3.2.0.14/compat'
    make[2]: Entering directory `/usr/src/squid-3.2.0.14/compat'
    (...)
    make[2]: Nothing to be done for `install-data-am'.
    make[2]: Leaving directory `/usr/src/squid-3.2.0.14'
    make[1]: Leaving directory `/usr/src/squid-3.2.0.14'

  36. W konfiguracji Squida włączasz transparent proxy na porcie 8080
    + sed -i 's/http_port 3128/http_port 3128\nhttp_port 8080 transparent/' /usr/local/squid/etc/squid.conf

  37. W konfiguracji Squida włączasz katalog cache
    + sed -i 's/#cache_dir ufs \/usr\/local\/squid\/var\/cache\/squid 100/cache_dir ufs \/usr\/local\/squid\/var\/cache\/squid 1000/' /usr/local/squid/etc/squid.conf

  38. Ustawiasz prawa dostępu dla Squida do katalaogów
    + chown nobody.nogroup /usr/local/squid/var/ -R

  39. Tworzysz pliki, w których będa przechowywane dodatkowe dane konfiguracji Squida
    + echo -n '' >/etc/squid.acl
    + echo -n '' >/etc/squid.mark


  40. Dopisujesz te pliki, do konfiguracji Squida
    + echo 'include /etc/squid.acl' >>/usr/local/squid/etc/squid.conf
    + echo 'include /etc/squid.mark' >>/usr/local/squid/etc/squid.conf


  41. Przy starcie systemu należy wykasować plik squid.pid jeśli on istnieje
    + echo 'rm /usr/local/squid/var/run/squid.pid' >>/etc/rc.d/rc.local

  42. Przy starcie systemu wystartuj Squida
    + echo /usr/local/squid/sbin/squid -D >>/etc/rc.d/rc.local

  43. Utwórz katalogi cache dla Squida
    + /usr/local/squid/sbin/squid -z
    Powinieneś otrzymać:
    2012/01/17 20:54:09 kid1| Creating Swap Directories
    2012/01/17 20:54:09 kid1| /usr/local/squid/var/cache/squid exists
    2012/01/17 20:54:09 kid1| Making directories in /usr/local/squid/var/cache/squid/00
    2012/01/17 20:54:09 kid1| Making directories in /usr/local/squid/var/cache/squid/01
    2012/01/17 20:54:09 kid1| Making directories in /usr/local/squid/var/cache/squid/02
    2012/01/17 20:54:09 kid1| Making directories in /usr/local/squid/var/cache/squid/03
    2012/01/17 20:54:09 kid1| Making directories in /usr/local/squid/var/cache/squid/04
    2012/01/17 20:54:09 kid1| Making directories in /usr/local/squid/var/cache/squid/05
    2012/01/17 20:54:09 kid1| Making directories in /usr/local/squid/var/cache/squid/06
    2012/01/17 20:54:09 kid1| Making directories in /usr/local/squid/var/cache/squid/07
    2012/01/17 20:54:09 kid1| Making directories in /usr/local/squid/var/cache/squid/08
    2012/01/17 20:54:09 kid1| Making directories in /usr/local/squid/var/cache/squid/09
    2012/01/17 20:54:10 kid1| Making directories in /usr/local/squid/var/cache/squid/0A
    2012/01/17 20:54:10 kid1| Making directories in /usr/local/squid/var/cache/squid/0B
    2012/01/17 20:54:10 kid1| Making directories in /usr/local/squid/var/cache/squid/0C
    2012/01/17 20:54:10 kid1| Making directories in /usr/local/squid/var/cache/squid/0D
    2012/01/17 20:54:10 kid1| Making directories in /usr/local/squid/var/cache/squid/0E
    2012/01/17 20:54:10 kid1| Making directories in /usr/local/squid/var/cache/squid/0F

  44. Restartujesz system ze swoim nowo skompilowanym jądrem z IMQ oraz z zainstalowanym Squidem




Nieco informacji na tematy poruszany w tym dokumencie znajdziesz na:

Po polsku:

Po angielsku:

Jeśli masz jakieś uwagi, pytania bądź propozycje to pisz na leszek małpa teczowe kropka eu kropka org. Jeśli znalazłeś tu jakiś błąd to napisz koniecznie. Inne wersje tego dokumentu znajdziesz na alfa.tailor.com.pl/imqhtb/imq_htb.html. Pliki użyte w tym dokumencie (poza jądrem i Squidem ) znajdziesz na alfa.tailor.com.pl/imqhtb/3.1.9. Jeśli nie chce Ci się wpisywać tych wszystkich poleceń to możesz użyć skryptów kernel.

Treść tego dokumentu jest udostępniana na podwójnej licencji:

Leszek Żur