# Can't initialize iptables table `nat'

## noodles006

I'm trying to set up my laptop to be able to share its wireless connection over ethernet following this guide: http://xmodulo.com/internet-connection-sharing-iptables-linux.html

Whenever I run 

```
sudo iptables -t nat -X
```

, I get the following error: 

```
iptables v1.6.1: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)

Perhaps iptables or your kernel needs to be upgraded.
```

I reinstalled iptables with the nftables use flags enabled, and enabled the NFT_NAT module in the kernel. Here is the output of searching NFT_NAT:

```
 Symbol: NFT_NAT [=m]                                                                                                                           │

  │ Type  : tristate                                                                                                                               │

  │ Prompt: Netfilter nf_tables nat module                                                                                                         │

  │   Location:                                                                                                                                    │

  │     -> Networking support (NET [=y])                                                                                                           │

  │       -> Networking options                                                                                                                    │

  │         -> Network packet filtering framework (Netfilter) (NETFILTER [=y])                                                                     │

  │           -> Core Netfilter Configuration                                                                                                      │

  │ (1)         -> Netfilter nf_tables support (NF_TABLES [=m])                                                                                    │

  │   Defined at net/netfilter/Kconfig:536                                                                                                         │

  │   Depends on: NET [=y] && INET [=y] && NETFILTER [=y] && NF_TABLES [=m] && NF_CONNTRACK [=m]                                                   │

  │   Selects: NF_NAT [=m]
```

But I still get the same error message. I also initially compiled the kernel with genkernel all. What else do I need to enable?

----------

## toralf

maybe CONFIG_NETFILTER_XT_NAT ?

----------

## noodles006

It says I have that enabled as a module

```
Symbol: NETFILTER_XT_NAT [=m]                                                                                                                  │  

  │ Type  : tristate                                                                                                                               │  

  │ Prompt: "SNAT and DNAT" targets support                                                                                                        │  

  │   Location:                                                                                                                                    │  

  │     -> Networking support (NET [=y])                                                                                                           │  

  │       -> Networking options                                                                                                                    │  

  │         -> Network packet filtering framework (Netfilter) (NETFILTER [=y])                                                                     │  

  │           -> Core Netfilter Configuration                                                                                                      │  

  │ (1)         -> Netfilter Xtables support (required for ip_tables) (NETFILTER_XTABLES [=y])                                                     │  

  │   Defined at net/netfilter/Kconfig:835                                                                                                         │  

  │   Depends on: NET [=y] && INET [=y] && NETFILTER [=y] && NETFILTER_XTABLES [=y] && NF_NAT [=m]                                                 │  

  │   Selected by: IP_NF_NAT [=m] && NET [=y] && INET [=y] && NETFILTER [=y] && IP_NF_IPTABLES [=m] && NF_CONNTRACK_IPV4 [=m] || IP6_NF_NAT [=n] &
```

----------

## NeddySeagoon

noodles006,

What does 

```
uname -a
```

 say.

Maybe you are not using the kernel you think you are?

The date/time is the build date/time of the running kernel.

----------

## noodles006

You're right, I'm still using the older kernel. I have been runningn "make menuconfig", "make && make modules_install", and "make install", as root in /usr/src/linux. What do I need to do to make the system use the newer kernel build?

----------

## NeddySeagoon

noodles006,

```
mount /boot
```

before the make install.

You will need to tell grub about the new kernel if the file name in boot has changed.

----------

## 1clue

 *noodles006 wrote:*   

> You're right, I'm still using the older kernel. I have been runningn "make menuconfig", "make && make modules_install", and "make install", as root in /usr/src/linux. What do I need to do to make the system use the newer kernel build?

 

What boot loader are you using?

Is your /boot directory a partition?

Did you mount the /boot partition before you did make install?

If you're using grub AND your /boot partition was mounted when you did 'make install' then:

```

mount /boot

grub-mkconfig > /boot/grub/grub.cfg

reboot

```

----------

## noodles006

I'm using GRUB, and I had the /boot partition mounted before running make install. I ran 

```
grub-mkconfig > /boot/grub/grub.cfg 
```

 before rebooting, but I still have the same output from "uname -a".

----------

## NeddySeagoon

noodles006,

Post the output of 

```
ls -l /boot
```

and the content of grub.cfg

----------

## noodles006

/boot:

```
total 63664

-rwxr-xr-x 1 root root   148137 Feb 22 16:28 config-4.9.76-gentoo-r1

-rwxr-xr-x 1 root root   148137 Feb 22 16:18 config-4.9.76-gentoo-r1.old

drwxr-xr-x 3 root root      512 Jan 18 15:50 EFI

drwxr-xr-x 6 root root      512 Jan 22 21:50 grub

-rwxr-xr-x 1 root root 39056740 Jan 18 06:00 initramfs-genkernel-x86_64-4.9.76-gentoo-r1

-rwxr-xr-x 1 root root  5403216 Jan 18 04:15 kernel-genkernel-x86_64-4.9.76-gentoo-r1

-rwxr-xr-x 1 root root  3208470 Feb 22 16:28 System.map-4.9.76-gentoo-r1

-rwxr-xr-x 1 root root  3208470 Feb 22 16:18 System.map-4.9.76-gentoo-r1.old

-rwxr-xr-x 1 root root  3208470 Jan 18 04:15 System.map-genkernel-x86_64-4.9.76-gentoo-r1

-rwxr-xr-x 1 root root  5403216 Feb 22 16:28 vmlinuz-4.9.76-gentoo-r1

-rwxr-xr-x 1 root root  5403216 Feb 22 16:18 vmlinuz-4.9.76-gentoo-r1.old
```

Grub.cfg:

```
#

# DO NOT EDIT THIS FILE

#

# It is automatically generated by grub-mkconfig using templates

# from /etc/grub.d and settings from /etc/default/grub

#

### BEGIN /etc/grub.d/00_header ###

if [ -s $prefix/grubenv ]; then

  load_env

fi

if [ "${next_entry}" ] ; then

   set default="${next_entry}"

   set next_entry=

   save_env next_entry

   set boot_once=true

else

   set default="0"

fi

if [ x"${feature_menuentry_id}" = xy ]; then

  menuentry_id_option="--id"

else

  menuentry_id_option=""

fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then

  set saved_entry="${prev_saved_entry}"

  save_env saved_entry

  set prev_saved_entry=

  save_env prev_saved_entry

  set boot_once=true

fi

function savedefault {

  if [ -z "${boot_once}" ]; then

    saved_entry="${chosen}"

    save_env saved_entry

  fi

}

function load_video {

  if [ x$feature_all_video_module = xy ]; then

    insmod all_video

  else

    insmod efi_gop

    insmod efi_uga

    insmod ieee1275_fb

    insmod vbe

    insmod vga

    insmod video_bochs

    insmod video_cirrus

  fi

}

if [ x$feature_default_font_path = xy ] ; then

   font=unicode

else

insmod part_gpt

insmod ext2

set root='hd0,gpt4'

if [ x$feature_platform_search_hint = xy ]; then

  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt4 --hint-efi=hd0,gpt4 --hint-baremetal=ahci0,gpt4  c4747800-c5ce-41f4-ad21-493cc776c002

else

  search --no-floppy --fs-uuid --set=root c4747800-c5ce-41f4-ad21-493cc776c002

fi

    font="/usr/share/grub/unicode.pf2"

fi

if loadfont $font ; then

  set gfxmode=auto

  load_video

  insmod gfxterm

  set locale_dir=$prefix/locale

  set lang=en_US

  insmod gettext

fi

terminal_output gfxterm

if [ x$feature_timeout_style = xy ] ; then

  set timeout_style=menu

  set timeout=5

# Fallback normal timeout code in case the timeout_style feature is

# unavailable.

else

  set timeout=5

fi

### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/10_linux ###

menuentry 'Gentoo GNU/Linux' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-c4747800-c5ce-41f4-ad21-493cc776c002' {

   load_video

   if [ "x$grub_platform" = xefi ]; then

      set gfxpayload=keep

   fi

   insmod gzio

   insmod part_gpt

   insmod fat

   set root='hd0,gpt2'

   if [ x$feature_platform_search_hint = xy ]; then

     search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  AB09-1E8D

   else

     search --no-floppy --fs-uuid --set=root AB09-1E8D

   fi

   echo   'Loading Linux x86_64-4.9.76-gentoo-r1 ...'

   linux   /kernel-genkernel-x86_64-4.9.76-gentoo-r1 root=UUID=c4747800-c5ce-41f4-ad21-493cc776c002 ro  

   echo   'Loading initial ramdisk ...'

   initrd   /initramfs-genkernel-x86_64-4.9.76-gentoo-r1

}

submenu 'Advanced options for Gentoo GNU/Linux' $menuentry_id_option 'gnulinux-advanced-c4747800-c5ce-41f4-ad21-493cc776c002' {

   menuentry 'Gentoo GNU/Linux, with Linux x86_64-4.9.76-gentoo-r1' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-x86_64-4.9.76-gentoo-r1-advanced-c4747800-c5ce-41f4-ad21-493cc776c002' {

      load_video

      if [ "x$grub_platform" = xefi ]; then

         set gfxpayload=keep

      fi

      insmod gzio

      insmod part_gpt

      insmod fat

      set root='hd0,gpt2'

      if [ x$feature_platform_search_hint = xy ]; then

        search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  AB09-1E8D

      else

        search --no-floppy --fs-uuid --set=root AB09-1E8D

      fi

      echo   'Loading Linux x86_64-4.9.76-gentoo-r1 ...'

      linux   /kernel-genkernel-x86_64-4.9.76-gentoo-r1 root=UUID=c4747800-c5ce-41f4-ad21-493cc776c002 ro  

      echo   'Loading initial ramdisk ...'

      initrd   /initramfs-genkernel-x86_64-4.9.76-gentoo-r1

   }

   menuentry 'Gentoo GNU/Linux, with Linux x86_64-4.9.76-gentoo-r1 (recovery mode)' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-x86_64-4.9.76-gentoo-r1-recovery-c4747800-c5ce-41f4-ad21-493cc776c002' {

      load_video

      if [ "x$grub_platform" = xefi ]; then

         set gfxpayload=keep

      fi

      insmod gzio

      insmod part_gpt

      insmod fat

      set root='hd0,gpt2'

      if [ x$feature_platform_search_hint = xy ]; then

        search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  AB09-1E8D

      else

        search --no-floppy --fs-uuid --set=root AB09-1E8D

      fi

      echo   'Loading Linux x86_64-4.9.76-gentoo-r1 ...'

      linux   /kernel-genkernel-x86_64-4.9.76-gentoo-r1 root=UUID=c4747800-c5ce-41f4-ad21-493cc776c002 ro single 

      echo   'Loading initial ramdisk ...'

      initrd   /initramfs-genkernel-x86_64-4.9.76-gentoo-r1

   }

   menuentry 'Gentoo GNU/Linux, with Linux 4.9.76-gentoo-r1' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.9.76-gentoo-r1-advanced-c4747800-c5ce-41f4-ad21-493cc776c002' {

      load_video

      if [ "x$grub_platform" = xefi ]; then

         set gfxpayload=keep

      fi

      insmod gzio

      insmod part_gpt

      insmod fat

      set root='hd0,gpt2'

      if [ x$feature_platform_search_hint = xy ]; then

        search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  AB09-1E8D

      else

        search --no-floppy --fs-uuid --set=root AB09-1E8D

      fi

      echo   'Loading Linux 4.9.76-gentoo-r1 ...'

      linux   /vmlinuz-4.9.76-gentoo-r1 root=UUID=c4747800-c5ce-41f4-ad21-493cc776c002 ro  

      echo   'Loading initial ramdisk ...'

      initrd   /initramfs-genkernel-x86_64-4.9.76-gentoo-r1

   }

   menuentry 'Gentoo GNU/Linux, with Linux 4.9.76-gentoo-r1 (recovery mode)' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.9.76-gentoo-r1-recovery-c4747800-c5ce-41f4-ad21-493cc776c002' {

      load_video

      if [ "x$grub_platform" = xefi ]; then

         set gfxpayload=keep

      fi

      insmod gzio

      insmod part_gpt

      insmod fat

      set root='hd0,gpt2'

      if [ x$feature_platform_search_hint = xy ]; then

        search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  AB09-1E8D

      else

        search --no-floppy --fs-uuid --set=root AB09-1E8D

      fi

      echo   'Loading Linux 4.9.76-gentoo-r1 ...'

      linux   /vmlinuz-4.9.76-gentoo-r1 root=UUID=c4747800-c5ce-41f4-ad21-493cc776c002 ro single 

      echo   'Loading initial ramdisk ...'

      initrd   /initramfs-genkernel-x86_64-4.9.76-gentoo-r1

   }

   menuentry 'Gentoo GNU/Linux, with Linux 4.9.76-gentoo-r1.old' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.9.76-gentoo-r1.old-advanced-c4747800-c5ce-41f4-ad21-493cc776c002' {

      load_video

      if [ "x$grub_platform" = xefi ]; then

         set gfxpayload=keep

      fi

      insmod gzio

      insmod part_gpt

      insmod fat

      set root='hd0,gpt2'

      if [ x$feature_platform_search_hint = xy ]; then

        search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  AB09-1E8D

      else

        search --no-floppy --fs-uuid --set=root AB09-1E8D

      fi

      echo   'Loading Linux 4.9.76-gentoo-r1.old ...'

      linux   /vmlinuz-4.9.76-gentoo-r1.old root=UUID=c4747800-c5ce-41f4-ad21-493cc776c002 ro  

      echo   'Loading initial ramdisk ...'

      initrd   /initramfs-genkernel-x86_64-4.9.76-gentoo-r1

   }

   menuentry 'Gentoo GNU/Linux, with Linux 4.9.76-gentoo-r1.old (recovery mode)' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.9.76-gentoo-r1.old-recovery-c4747800-c5ce-41f4-ad21-493cc776c002' {

      load_video

      if [ "x$grub_platform" = xefi ]; then

         set gfxpayload=keep

      fi

      insmod gzio

      insmod part_gpt

      insmod fat

      set root='hd0,gpt2'

      if [ x$feature_platform_search_hint = xy ]; then

        search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  AB09-1E8D

      else

        search --no-floppy --fs-uuid --set=root AB09-1E8D

      fi

      echo   'Loading Linux 4.9.76-gentoo-r1.old ...'

      linux   /vmlinuz-4.9.76-gentoo-r1.old root=UUID=c4747800-c5ce-41f4-ad21-493cc776c002 ro single 

      echo   'Loading initial ramdisk ...'

      initrd   /initramfs-genkernel-x86_64-4.9.76-gentoo-r1

   }

}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###

### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/30_os-prober ###

### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/40_custom ###

# This file provides an easy way to add custom menu entries.  Simply type the

# menu entries you want to add after this comment.  Be careful not to change

# the 'exec tail' line above.

### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###

if [ -f  ${config_directory}/custom.cfg ]; then

  source ${config_directory}/custom.cfg

elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then

  source $prefix/custom.cfg;

fi

### END /etc/grub.d/41_custom ###

```

----------

## NeddySeagoon

noodles006,

Its difficult to quote grub.cfg

```
menuentry 'Gentoo GNU/Linux'

...

   echo   'Loading Linux x86_64-4.9.76-gentoo-r1 ...'

   linux   /kernel-genkernel-x86_64-4.9.76-gentoo-r1 root=UUID=c4747800-c5ce-41f4-ad21-493cc776c002 ro 

   echo   'Loading initial ramdisk ...'

   initrd   /initramfs-genkernel-x86_64-4.9.76-gentoo-r1 
```

is your original Genkernel kernel.

You need to go into the 

```
 submenu 'Advanced options for Gentoo GNU/Linux' 
```

Then there is    

```
menuentry 'Gentoo GNU/Linux, with Linux 4.9.76-gentoo-r1' 

      echo   'Loading Linux 4.9.76-gentoo-r1 ...'

      linux   /vmlinuz-4.9.76-gentoo-r1 root=UUID=c4747800-c5ce-41f4-ad21-493cc776c002 ro 

      echo   'Loading initial ramdisk ...'

      initrd   /initramfs-genkernel-x86_64-4.9.76-gentoo-r1 
```

That loads your new kernel with the original initrd, which may or may not work because the old modules in the initrd may not match the new kernel.

You can read all about it in dmesg.

If you want to do it cleanly, have genkernel do it all and make a new initrd too, or make a kernel by hand that does not require an initrd.

----------

## noodles006

This seems to work, thank you very much! I will also look into making a kernel by hand.

----------

