How to set url object attributes in Drupal 8.

You have a link as an url object. You need to override its attributes in a preprocess.
<?php

/**
 * Implements hook_preprocess_HOOK() for node.html.twig.
 */
function theme_preprocess_node(&$variables) {
  if (!empty(
$variables['content']['field_name'])) {
   
$options = $variables['content']['field_name'][0]['#url']->getOptions();
   
$options['attributes']['target'] = '_blank';
   
$variables['content']['field_name'][0]['#url']->setOptions($options);
  }
}

?>