# Unstable network in Hyper-V



## Non Hic (Oct 1, 2016)

I used the ready made .ISO image from freebsd.org for the Hyper-V machine. I have issues with unstable networking. The network sometimes works, sometimes doesn't. I have no idea why.

When it doesn't work, if I try `ifconfig de0 down/up` and `dhclient de0` it comes up... works for a while then if I leave the machine a few minutes, it goes down again. For example `ping google.com` won't work at all. Strange thing is everything shows "OK". The screenshots here I provide is from "ifconfig""resolve.conf""netstat -r", these are taken while "ping google.com" does NOT work.

Oh, and when it doesn't work... if I leave it alone, after a while, it works again! Very strange!

Strange thing I noticed, when the network doesn't work, if I write "netstat -r", it takes a long time, maybe 10-20 seconds for it to answer... but when it works, "netstat -r" responds very quickly, less than a second.

Any ideas what to do? 

Ps. I'm sorry I post screenshots instead of text but I have no idea how to copy/paste from Hyper-V console. 


```
ifconfig_de0="SYNCDHCP"
```

When things "work", this is what I see:


```
root@freebsd.home:~ # ifconfig
de0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        ether 00:15:5d:01:57:0b
        inet 192.168.1.81 netmask 0xffffff00 broadcast 192.168.1.255
        nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
        media: Ethernet autoselect (100baseTX)
        status: active
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
        options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
        inet 127.0.0.1 netmask 0xff000000
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
```


```
root@freebsd.home:~ # netstat -r
Routing tables

Internet:
Destination        Gateway            Flags      Netif Expire
default            192.168.1.1        UGS         de0
localhost          link#2             UH          lo0
192.168.1.0        link#1             U           de0
192.168.1.81       link#1             UHS         lo0

Internet6:
Destination        Gateway            Flags      Netif Expire
::                 localhost          UGRS        lo0
localhost          link#2             UH          lo0
::ffff:0.0.0.0     localhost          UGRS        lo0
fe80::             localhost          UGRS        lo0
fe80::%lo0         link#2             U           lo0
fe80::1%lo0        link#2             UHS         lo0
ff01::%lo0         localhost          U           lo0
ff02::             localhost          UGRS        lo0
ff02::%lo0         localhost          U           lo0
```
My resolv.conf


```
# Generated by resolvconf
search lan
# nameserver 192.168.1.1
nameserver 8.8.8.8
nameserver 8.8.4.4
```


----------



## SemFLY (Oct 1, 2016)

Hi ))
Do you create virtual switch in the Hyper-V ?

Ahh... sorry, reading quick you message... sometimes network is down....


----------



## SemFLY (Oct 1, 2016)

What model network card on host ?

If realtek - update driver
If you use VLAN, don't use program create and manage VLAN's for network card, set nubmer VLAN in Hyper-V on the interface

And one more, on host turn off firewall

In VM use options for interface

```
# ifconfig de0 -tso
```

*P.S.*
Star sshd service and connect to virtual machine from putty program
edit sshd_config
uncomment options

```
# ee /etc/ssh/sshd_config
...
PermitRootLogin yes
UseDNS no
...
```

Save and restart service


```
# service sshd restart
```

Try connect from putty
And from putty you can copy text.


----------



## Non Hic (Oct 1, 2016)

Thank you very much for the sshd help!!! (It was on my list of questions! haha)... and oh dear God, "ee" is MUCH nicer than "vi". I have used "vi" until now! *newbie to FreeBSD, trying to move "run" away from Windows 10*

About the VLAN... I should explain that I do not use a VLAN but I have another virtual Windows 10 machine in the same host without VLAN which works without any issues. If I enable VLAND, the Windows 10 machine loses its network connection so I'm guessing if I use VLAN ID for the BSD machine, the result would be the same and it wouldn't work.

(The firewall on the host machine has not much to do with the virtual ones because my *virtual* Windows 10 works with the host firewall active without issues and if it was the firewall, I would get no connection at all, not an unstable which comes and goes so I'm guessing it is not a firewall issue either.)

So I'm a little confused here, are you suggesting that I "MUST" have a VLAN ID for it to work? (I tried it, no luck) ... also, I do get internet connection in the FreeBSD virtual machine but it comes and goes, very strange. I don't think it has anything to do with VLAN, however?

I also tried "ifconfig de0 -tso" and it gives me error "-tso invalid argument"?


----------



## Non Hic (Oct 1, 2016)

Addendum: I now enabled sshd and I'm logged into it using putty... so hmmmmmmmmmmmmm... the network is working? Well, it seems that the local network works fine but the "internet" doesn't work. I mean, I'm in putty as root in it but can't `ping google.com`!


```
root@freebsd.home:~ # ifconfig
de0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        ether 00:15:5d:01:57:0b
        inet 192.168.1.81 netmask 0xffffff00 broadcast 192.168.1.255
        nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
        media: Ethernet autoselect (100baseTX)
        status: active
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
        options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
        inet 127.0.0.1 netmask 0xff000000
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
```


```
root@freebsd.home:~ # ping google.com
ping: cannot resolve google.com: Host name lookup failure
```


----------



## Non Hic (Oct 1, 2016)

*EDIT:* Scratch the below. Now I can't ping the IP or connect to PuTTY either. VERY ODD. It comes and goes! I'm totally lost now. 

*EDIT2:* "Ping: Sendto: No buffer space available" 

Hm!!! I can't believe I didn't test this... it seems that I can "ping <IP>" but not "ping <host>" so I'm guessing this might be a DNS issue and not a "networking" issue. What can be wrong? I have set Google DNS in my resolv.conf but I have also tried my own router's DNS, same problems. It "comes and goes".


```
# Generated by resolvconf
search lan
# nameserver 192.168.1.1
nameserver 8.8.8.8
nameserver 8.8.4.4
```

...and I have this in rc.conf


```
ifconfig_de0="SYNCDHCP"
```


----------



## Non Hic (Oct 1, 2016)

Doing the `ifconfig de0 down` `ifconfig de0 up` makes it work... for a while, then it goes away again.  ...before doing that, there is an odd flag for de0 when I type `ifconfig` which is "OACTIVE" ??? but after that, it shows "RUNNING".


```
de0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
```


----------



## Non Hic (Oct 1, 2016)

Now I can't ping "google.com" or "ping <ip>" but ifconfig shows active!!!


```
root@freebsd.home:~ # ifconfig
de0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        ether 00:15:5d:01:57:0b
        inet 192.168.1.81 netmask 0xffffff00 broadcast 192.168.1.255
        nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
        media: Ethernet autoselect (100baseTX)
        status: active
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
        options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
        inet 127.0.0.1 netmask 0xff000000
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
```
...and doing "netstat -r" takes 30-40 seconds, like it's "stuck"... and it answers this:


```
root@freebsd.home:~ # netstat -r
Routing tables

Internet:
Destination        Gateway            Flags      Netif Expire
default            192.168.1.1        UGS         de0
localhost          link#2             UH          lo0
192.168.1.0        link#1             U           de0
192.168.1.81       link#1             UHS         lo0

Internet6:
Destination        Gateway            Flags      Netif Expire
::                 localhost          UGRS        lo0
localhost          link#2             UH          lo0
::ffff:0.0.0.0     localhost          UGRS        lo0
fe80::             localhost          UGRS        lo0
fe80::%lo0         link#2             U           lo0
fe80::1%lo0        link#2             UHS         lo0
ff01::%lo0         localhost          U           lo0
ff02::             localhost          UGRS        lo0
ff02::%lo0         localhost          U           lo0
```
*I have zero idea what can be wrong!* The other virtual Windows 10 machine is working just fine so I mean, the internet is on, everything is "OK" so whatever it is, it must be in the FreeBSD machine somewhere.


----------



## Non Hic (Oct 1, 2016)

I did a "ps aux" and maybe it is the "dhclient" which just crashes????


```
root@freebsd.home:~ # ps aux
USER PID  %CPU %MEM   VSZ  RSS TT  STAT STARTED      TIME COMMAND
root  11 700.0  0.0     0  112  -  RL    5:56PM 104:32.25 [idle]
root  12   0.1  0.0     0  496  -  WL    5:56PM   0:05.56 [intr]
root   0   0.0  0.0     0  208  -  DLs   5:56PM   0:00.02 [kernel]
root   1   0.0  0.0  9492  916  -  ILs   5:56PM   0:00.01 /sbin/init --
root   2   0.0  0.0     0   48  -  DL    5:56PM   0:00.05 [cam]
root   3   0.0  0.0     0   16  -  DL    5:56PM   0:00.01 [fdc0]
root   4   0.0  0.0     0   16  -  DL    5:56PM   0:00.00 [sctp_iterator]
root   5   0.0  0.0     0   32  -  DL    5:56PM   0:00.01 [pagedaemon]
root   6   0.0  0.0     0   16  -  DL    5:56PM   0:00.00 [vmdaemon]
root   7   0.0  0.0     0   16  -  DL    5:56PM   0:00.00 [pagezero]
root   8   0.0  0.0     0   32  -  DL    5:56PM   0:00.01 [bufdaemon]
root   9   0.0  0.0     0   16  -  DL    5:56PM   0:00.02 [syncer]
root  10   0.0  0.0     0   16  -  DL    5:56PM   0:00.00 [audit]
root  13   0.0  0.0     0   48  -  DL    5:56PM   0:00.01 [geom]
root  14   0.0  0.0     0   16  -  DL    5:56PM   0:00.13 [rand_harvestq]
root  15   0.0  0.0     0   16  -  DL    5:56PM   0:00.00 [vnlru]
root 348   0.0  0.1 12372 2004  -  Ss    5:56PM   0:00.14 /usr/sbin/hv_kvp_daemon
root 349   0.0  0.2 13628 4944  -  Is    5:56PM   0:00.00 /sbin/devd
root 423   0.0  0.1 14520 2112  -  Ss    5:56PM   0:00.00 /usr/sbin/syslogd -s
root 615   0.0  0.3 61312 6608  -  Is    5:56PM   0:00.00 /usr/sbin/sshd
root 619   0.0  0.1 16624 2248  -  Is    5:56PM   0:00.00 /usr/sbin/cron -s
root 749   0.0  0.3 86580 7188  -  Ss    6:01PM   0:00.13 sshd: root@pts/0 (sshd)
root 761   0.0  0.1 14520 1980 v0  Is+   6:03PM   0:00.00 /usr/libexec/getty Pc ttyv0
root 671   0.0  0.1 14520 1980 v1  Is+   5:56PM   0:00.00 /usr/libexec/getty Pc ttyv1
root 752   0.0  0.2 23600 3444  0  Ss    6:01PM   0:00.02 -csh (csh)
root 778   0.0  0.1 18768 2192  0  R+    6:11PM   0:00.00 ps aux
```
I typed "dhclient de0" and I got:

```
root@freebsd.home:~ # ps aux
USER  PID  %CPU %MEM   VSZ  RSS TT  STAT STARTED      TIME COMMAND
root   11 700.0  0.0     0  112  -  RL    5:56PM 107:37.66 [idle]
root   12   0.2  0.0     0  496  -  WL    5:56PM   0:05.79 [intr]
root    0   0.0  0.0     0  208  -  DLs   5:56PM   0:00.02 [kernel]
root    1   0.0  0.0  9492  916  -  SLs   5:56PM   0:00.01 /sbin/init --
root    2   0.0  0.0     0   48  -  DL    5:56PM   0:00.05 [cam]
root    3   0.0  0.0     0   16  -  DL    5:56PM   0:00.01 [fdc0]
root    4   0.0  0.0     0   16  -  DL    5:56PM   0:00.00 [sctp_iterator]
root    5   0.0  0.0     0   32  -  DL    5:56PM   0:00.01 [pagedaemon]
root    6   0.0  0.0     0   16  -  DL    5:56PM   0:00.00 [vmdaemon]
root    7   0.0  0.0     0   16  -  DL    5:56PM   0:00.00 [pagezero]
root    8   0.0  0.0     0   32  -  DL    5:56PM   0:00.02 [bufdaemon]
root    9   0.0  0.0     0   16  -  DL    5:56PM   0:00.02 [syncer]
root   10   0.0  0.0     0   16  -  DL    5:56PM   0:00.00 [audit]
root   13   0.0  0.0     0   48  -  DL    5:56PM   0:00.01 [geom]
root   14   0.0  0.0     0   16  -  DL    5:56PM   0:00.14 [rand_harvestq]
root   15   0.0  0.0     0   16  -  DL    5:56PM   0:00.00 [vnlru]
root  348   0.0  0.1 12372 2004  -  Ss    5:56PM   0:00.14 /usr/sbin/hv_kvp_daemon
root  349   0.0  0.2 13628 4944  -  Ss    5:56PM   0:00.00 /sbin/devd
root  423   0.0  0.1 14520 2112  -  Ss    5:56PM   0:00.00 /usr/sbin/syslogd -s
root  615   0.0  0.3 61312 6608  -  Is    5:56PM   0:00.00 /usr/sbin/sshd
root  619   0.0  0.1 16624 2248  -  Ss    5:56PM   0:00.00 /usr/sbin/cron -s
root  749   0.0  0.3 86580 7188  -  Ss    6:01PM   0:00.15 sshd: root@pts/0 (sshd)
root  782   0.0  0.1 14656 2276  -  Ss    6:12PM   0:00.00 dhclient: de0 [priv] (dhclient)
_dhcp 840   0.0  0.1 14656 2388  -  Ss    6:12PM   0:00.00 dhclient: de0 (dhclient)
root  761   0.0  0.1 14520 1980 v0  Is+   6:03PM   0:00.00 /usr/libexec/getty Pc ttyv0
root  671   0.0  0.1 14520 1980 v1  Is+   5:56PM   0:00.00 /usr/libexec/getty Pc ttyv1
root  752   0.0  0.2 23600 3444  0  Ss    6:01PM   0:00.02 -csh (csh)
root  841   0.0  0.1 18768 2192  0  R+    6:12PM   0:00.00 ps aux
```
These two were missing:

```
root  782   0.0  0.1 14656 2276  -  Ss    6:12PM   0:00.00 dhclient: de0 [priv] (dhclient)
_dhcp 840   0.0  0.1 14656 2388  -  Ss    6:12PM   0:00.00 dhclient: de0 (dhclient)
```
...so now it works again!

*Hm, can it be that "dhclient" crashes?*
Is there any log file I can check?


----------



## Non Hic (Oct 1, 2016)

aaaaaaaargh... now I see "dhclient" running in "ps aux" (after a reboot) but network is "down", doesn't work!  ... but I did a "ifconfig de0 down/up" ... now I do NOT see "dhclient" in "ps aux"... BUT THE NETWORK NOW WORKS!!! There was no "OACTIVE" flag this time when it didn't work. Nothing makes sense! I can't find a pattern.

*I'm going insane, it seems total random!? *


----------



## Non Hic (Oct 2, 2016)

Hm, now several hours, while I left PuTTY connected, it has worked without issues. My guess is that the network "dies" if it isn't used? Can this be it? *Is there any setting to disable this?* ( I have disabled all power saving functions in the host machine. )


----------



## SemFLY (Oct 2, 2016)

No, i mean if you use VLAN, check all options with regards VLAN
But you don't have VLAN and don't use this, the question about vlan is removed

Next...

your network card detected as "de0"
de - is old driver, now in Hyper-V network card usually detected as hn (hh0, hn1, hn2 and etc.)
may be options -tso does't have old driver
What version FreeBSD you use ?
check this

```
# uname -a
```
Copy here...

DNS problem, may be.
Check port number 53 on your router and host machine.
When problem in Hyper-V ?
Check in this moment, DNS work on host ?

Open cmd in Windows
write command

```
C:\Windows\system32> nslookup freebsd.org
```
copy answer here...

About putty
putty will be work always, if netwrok card it's ok and ping on IP too.
because putty connect on IP and DNS not importand work or no.


I think all problem with network was, because you don't turn off saving function on host, this is very importand.
Check two - four days, but i think all will be work fine


----------



## Non Hic (Oct 3, 2016)

I used the image specially made for Hyper-V from freebsd.org so maybe that image is using old drivers.


```
root@freebsd.home:~ # uname -a
FreeBSD freebsd.home 10.3-RELEASE-p7 FreeBSD 10.3-RELEASE-p7 #0: Thu Aug 11 18:38:15 UTC 2016     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64
```

All power saving functions are off. Host machine, nslookup, all other virtual machines work fine also. It is only FreeBSD virtual machine which has this issue.

I left PuTTY connected to the virtual FreeBSD machine now since yesterday, everything works fine, no issues at all. It seems that perhaps FreeBSD turns the networking (or DNS) off if it is not used. Maybe it has to do with the older driver in it "de0".

I will await FreeBSD 11.x and try a fresh install, see if it will be better or not. 

Thank you for all the help!


----------



## Non Hic (Oct 3, 2016)

As a side note for others who might experience this issue. I tried "TrueOS" (Former PC-BSD), it has same problem as well. If the connection isn't used for a few minutes, it "dies" and won't come back again until you do an "ifconfig hn0 down/up" ("ifconfig de0 down/up")... so this issue is there even with "hn" new drivers.

Basically, you have to keep the connection "alive" with using it by connecting to PuTTY or something 24x7, otherwise it "dies", goes to sleep or whatever it seems to do.

*Odd issue, makes FreeBSD unsuable in Hyper-V.*

I'll keep digging but doesn't look bright.


----------



## SemFLY (Oct 3, 2016)

read this
https://blogs.technet.microsoft.com...rent-network-issues-mac-collisions-can-cause/

Under Hyper-V FreeBSD work is fine, i have two production server, under Hyper-V.
uptime 367 and 586 days, work 24x7

I think you must more good check hardware on host - network card, drivers, BIOS options(power saving) and etc.
May be special utils turn off network card, antivirus...

This don't magic, this is real hardware on host.

Try install another system, as guest... 
Example Windows Server 2012 R2 Standart or Windows 7 or Windows 10


----------



## Non Hic (Oct 4, 2016)

SemFLY, thank you for the suggestions and help but as I stated earlier, the host machine works 100% without problems. I have more guest machines in this host and they ALL work 100% without issues. The ONLY one which is having problem is FreeBSD. I tried both the ready made image downloaded from freebsd.org and even TrueOS, they both have this problem which means FreeBSD does not work well under Hyper-V. No errors, no logs, no help, nothing, zilch, zero, nada.

*( I have run Windows 8.x, 8.1, 7, 10, Linux, as guests in this machine and all work fine, only FreeBSD is the one having this problem. )*

I put many weeks on this issue, tried hard to move away from Windows but FreeBSD just is not a good operating system if it can have such issues without ANY errors, ANY indication, ANY hints, ANY anything!

They said FreeBSD is all that, I say, it is not all that. Sadly, I really gave it a good try. Maybe in a few years, I'll try again, until then, Windows it is then. (No, I won't go to Linux, I hate Linux!)

Over 20 years!!!... and still simple stuff like unstable networking which its problem CANNOT be found!!! Over 20 years!!! Insanity! Yes, I'm very annoyed. It's almost 2017, we have robots, we have autonomous cars... but FreeBSD cannot fix a simple stable network?

I must put weeks of my life on it? It's junk, it's unusable. ... and this is probably why it has such low marketshare. Free market forces... BSD is simply not good enough... Maybe in more 20 years. *lol*


----------

