# Network Configuration

## Goals
- default WAN port is used for link to local network with router
  - dhcp yes
- default LAN port is used for direct connection to laptop
  - either without ICS (Internet Connection Sharing) and link local addresses (169.254.xxx.xxx) without gateway
  - or with ICS and DHCP (192.168.137.xxx) and with gateway (laptop)

| Situation | Windows Ethernet | NanoPi | SSH | Internet NanoPi |
| - | - | - | - | - |
| home, connected to Router | *doesn't matter* | DHCP (192.168.2.x) | 192.168.2.x | with end0 over Router |
| direct Laptop, ICS | 192.168.137.1 | DHCP (192.168.137.x) | nanopi-r3s-lts.local | with enp1s0 over Laptop |
| direct Laptop, no ICS | 169.254.x.x | 169.254.x.x | nanopi-r3s-lts.local | no |

`/etc/netplan/30-ethernets-dhcp.yaml`:
```yaml
network:
  version: 2
  ethernets:
    end0:
      dhcp4: yes
      dhcp6: yes

    enp1s0:
      dhcp4: yes
      link-local:
        - ipv4
        - ipv6
      optional: true
```

:::warning
if direct connection to Laptop and then switching ICS on to off the NanoPi doesn't recognize the change - quickfix: disconnect/connect LAN cable
:::

## Install avahi daemon for mDNS service (to connect with <hostname> within link-local)
```bash
sudo apt update
sudo apt install avahi-daemon

# check
systemctl status avahi-daemon --no-pager

# typically NOT needed
sudo systemctl enable --now avahi-daemon
```

## disable EEE (Energy Efficient Ethernet)
```bash
sudo ethtool --set-eee end0 eee off
sudo ethtool --set-eee end0 eee on
sudo ethtool --show-eee end0
```
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9